public ActionResult AddToDo(string title, string description, DateTime date) { if (System.Text.RegularExpressions.Regex.IsMatch(title, "^[a-zA-Z]+$")) { var userId = User.Identity.GetUserId(); using (ApplicationDbContext db = new ApplicationDbContext()) { var entity = new ToDo(); entity.Title = title; entity.Description = description; entity.Date = date; entity.IsActive = true; db.ToDoes.Add(entity); db.SaveChanges(); var todomapping = new ToDoMapping(); todomapping.UserId = userId; todomapping.TodoId = entity.Id; todomapping.Date = date; db.ToDoMappings.Add(todomapping); db.SaveChanges(); return(RedirectToAction("ToDoList", "ToDo")); } } else { //title = title.Remove(title.Length - 1); Console.WriteLine("Enter only alphabets"); Console.ReadLine(); ModelState.AddModelError("", "Enter only alphabets"); } return(RedirectToAction("ToDoList", "ToDo")); }
/// <summary> /// This method is used to get details of the list by clicking on Title for specific id /// </summary> /// <param name="id"></param> /// <returns></returns> //Details public ActionResult Details(int id) { ApplicationDbContext db = new ApplicationDbContext(); ToDoMapping toDo = db.ToDoMappings.Single(x => x.TodoId == id); return(View(toDo)); }
public static async Task <IActionResult> CreateToDo( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "todo")] HttpRequest req, [Table("todos", Connection = "AzureWebJobsStorage")] IAsyncCollector <ToDoEntity> todoTable, [Queue("todo", Connection = "AzureWebJobsStorage")] IAsyncCollector <ToDoItem> todoQueue, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <ToDoItemRequest>(requestBody); var todoItem = new ToDoItem() { Description = data.Description, OwnerName = data.OwnerName }; await todoTable.AddAsync(ToDoMapping.MapToDoModelToEntity(todoItem)); await todoQueue.AddAsync(todoItem); return(new OkObjectResult(todoItem)); }
public HttpResponseMessage PostToDo(ToDoModel toDo) { ToDo toDoEntity = new ToDo(); using (ApplicationDbContext db = new ApplicationDbContext()) { if (toDo.Id == 0 || toDo.Id == null) { toDoEntity.Title = toDo.Title; toDoEntity.Description = toDo.Description; toDoEntity.Date = Convert.ToDateTime(toDo.date); toDoEntity.IsActive = true; db.ToDoes.Add(toDoEntity); db.SaveChanges(); ToDoMapping toDoMappingEntity = new ToDoMapping(); toDoMappingEntity.TodoId = toDoEntity.Id; //Need to modify this line after token generation toDoMappingEntity.UserId = toDo.UserId; //toDoMappingEntity.UserId = 10; db.ToDoMappings.Add(toDoMappingEntity); db.SaveChanges(); } else { //ToDo to = new ToDo(); var toDoEnity = db.ToDoes.Where(x => x.Id == toDo.Id).FirstOrDefault(); toDoEnity.Title = toDo.Title; toDoEnity.Description = toDo.Description; toDoEnity.Date = Convert.ToDateTime(toDo.date); db.SaveChanges(); } } var resultResponse = new { Id = toDoEntity.Id }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, resultResponse); return(response); }