Пример #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.AdditionalConditionDTO additionalConditionDTO = ((JObject)dtoItem).ToObject <DTO.AdditionalConditionDTO>();

            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = Createcontext())
                {
                    AdditionalCondition additionalCondition = new AdditionalCondition();

                    if (id == 0)
                    {
                        context.AdditionalCondition.Add(additionalCondition);
                    }

                    if (id > 0)
                    {
                        additionalCondition = context.AdditionalCondition.FirstOrDefault(o => o.AdditionalConditionID == id);

                        if (additionalCondition == null)
                        {
                            notification = new Notification {
                                Type = NotificationType.Error, Message = "Can't Find Data"
                            };
                            return(false);
                        }
                    }

                    this.converter.DTO2DB_AdditionalCondition(additionalConditionDTO, ref additionalCondition);
                    additionalCondition.UpdateDate = DateTime.Now;
                    additionalCondition.UpdateBy   = userId;
                    context.SaveChanges();
                    dtoItem = this.GetData(additionalCondition.AdditionalConditionID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Пример #2
0
 public void DTO2DB_AdditionalCondition(DTO.AdditionalConditionDTO dto, ref AdditionalCondition db)
 {
     AutoMapper.Mapper.Map <DTO.AdditionalConditionDTO, AdditionalCondition>(dto, db);
 }