public async Task <ActionResult> Create(FormCollection collection) { try { // TODO: Add insert logic here ToDo todo = new ToDo(Guid.NewGuid()) { Task = collection["Task"], DueDateTime = DateTime.Parse(collection["DueDateTime"]), CreatedBy = User.Identity.Name, CreatedWhen = DateTime.Now, Done = false, AssignedTo = User.Identity.Name }; await _todoRepository.Create(todo); return(RedirectToAction("Index")); } catch (Exception e) { Logger.Error(e, "Exception occured."); return(View()); } }
public async Task <ResultData> Post(CreateToDoRequest request) { var toDo = new ToDo(request); await _repository.Create(toDo); _unitOfWork.Commit(); return(SuccessData(EGenericOperations.Record_Saved_Successfully.GetDescription())); }
public async Task <ToDoVM> Add(CreateToDoVM item) { var toDo = mapper.Map <ToDo>(item); toDo.UserId = loginService.GetUser().Id; toDo.State = TaskState.New; await todoRepository.Create(toDo); await todoRepository.Save(); return(await Task.FromResult(mapper.Map <ToDoVM>(toDo))); }
private void Add(object parameter) { try { var myToDo = _ToDoRepository.Create(); this.DataList = _ToDoRepository.GetAll().ToList(); this.SelectedToDo = myToDo; } catch (Exception ex) { Logging.WriteLog("Fehler: " + ex.ToString()); MessageBox.Show("Fehler: " + ex.Message); } }
/// <summary> /// This is to add a new todo item /// Here we have used automapper to convert the domain model to DAL model /// </summary> /// <param name="item"></param> /// <returns>After adding todo item it will append the id in todo object and return that object</returns> public Domain.Models.ToDoItem Add(Domain.Models.ToDoItem item) { if (null != item) { //This is to initilize the automapper Mapper.Initialize(cfg => cfg.CreateMap <Domain.Models.ToDoItem, DataAccessLayer.Models.ToDoItem>()); //This is convert the Domain model to DAL model object, this will take domain model as parameter and return DAL model as response DataAccessLayer.Models.ToDoItem itemDAL = Mapper.Map <Domain.Models.ToDoItem, DataAccessLayer.Models.ToDoItem>(item); var record = _repository.Create(itemDAL); if (null != record) { item.Id = record.Id; } } return(item); }
public IActionResult Post([FromBody] ToDoDTO tododto) { { var todo = _mapper.Map <ToDo>(tododto); if (todo == null) { return(BadRequest()); } string name = HttpContext.User.Identity.Name; int userId = _repository.GetUserId(name); todo.Check = false; todo.UserId = userId; _repository.Create(todo); _repository.Save(); return(Ok()); } }
public ActionResult Create(ToDoItemVM model) { try { var ToDoItem = _mapper.Map<ToDoItem>(model); var isSuccess = _repo.Create(ToDoItem); if(!isSuccess) { ModelState.AddModelError("","Something went wrong"); return View(model); } return RedirectToAction(nameof(Index)); } catch { return View(); } }
public bool AddToDo([FromBody] IEnumerable <ToDoViewModel> toDo) { if (toDo == null) { return(false); //return BadRequest("Invalid passed data"); } if (!ModelState.IsValid) { return(false); // return BadRequest(ModelState); } try { _toDoRepository.Create(_mapper.Map <IEnumerable <ToDoViewModel>, IEnumerable <ToDo> >(toDo)); return(true); } catch (Exception ex) { return(false); } }
public ToDo Create(ToDo toDo) { return(_repository.Create(toDo)); }
public JsonResult Create(ToDoDto toDoItem) { toDoItem = toDoRepository.Create(toDoItem); return(Json(toDoItem)); }
public int Post([FromBody] ToDoDto toDoDto) { return(_toDoRepository.Create(toDoDto)); }
public IActionResult Create(ToDo todo) { todo = repositoryToDo.GetById(todo.id); repositoryToDo.Create(todo); return(RedirectToAction("Index")); }