示例#1
0
 /// <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;
             //This is to increment a cache
             _repositoryCache.Increment(_cacheKey);
         }
     }
     return(item);
 }