Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
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
C#
[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
C#
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,

                //SiteUserId= user.SiteUserId,
            };
            _context.ManageTask.Add(managetask);
            _`context.SaveChanges`();
        }

below is code for controller for add
C#
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();
                    }
                }
            }
        }
Posted
Updated 8-Mar-23 4:13am
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900