/// <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); }
/// <summary> /// This is to update todo item /// Here we have used automapper to convert the domain model to DAL model /// </summary> /// <param name="item"></param> /// <returns>After updating todo item, it will retrun true if it updated successfully otherwise false</returns> public bool Update(Domain.Models.ToDoItem item) { bool status = false; 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); int id = _repository.Update(itemDAL); if (id > 0) { status = true; } } return(status); }