what is the code for add data in redis database using hash datatype of redis in C# asp.net core 3.1?Also what is the concept of master key in it?
I have to analyse the code for add in api and rewrite the code for add so that my data should be added in redis database.
What I have tried:
below is code for add in api
[HttpPost]
[Route("AddTask")]
public ActionResult Add(TaskModel model)
{
if (ModelState.IsValid)
{
TaskRepository obj = new TaskRepository();
obj.AddTask(model);
obj.Save();
return Ok();
}
else
{
return BadRequest();
}
}
below is code for add in repository
public void AddTask(TaskModel user)
{
ManageTask managetask = new ManageTask()
{
description = user.description,
employeeId = user.employeeId,
reviewerId = user.reviewerId,
startdate = System.DateTime.UtcNow,
enddate = System.DateTime.UtcNow,
deadline = user.deadline,
productname = user.productname,
};
_context.ManageTask.Add(managetask);
_`context.SaveChanges`();
}
below is code for controller for add
public async Task<iactionresult> Add(TaskModel model)
{
using (HttpClient client = new HttpClient())
{
StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
string endpoint = "http://localhost:32883/api/employeetask/AddTask";
using (var Response = await client.PostAsync(endpoint, content))
{
if (Response.StatusCode == System.Net.HttpStatusCode.OK)
{
TempData[""] = JsonConvert.SerializeObject(model);
return RedirectToAction("GetAllTask");
}
else
{
ModelState.Clear();
ModelState.AddModelError(string.Empty, "server error");
return View();
}
}
}
}