예제 #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.CostInvoice2TypeDto costInvoice2TypeDto = ((JObject)dtoItem).ToObject <DTO.CostInvoice2TypeDto>();

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

            try
            {
                using (var context = CreatContext())
                {
                    CostInvoice2Type costInvoice2Type = new CostInvoice2Type();

                    if (id == 0)
                    {
                        context.CostInvoice2Type.Add(costInvoice2Type);
                    }
                    if (id > 0)
                    {
                        costInvoice2Type = context.CostInvoice2Type.FirstOrDefault(o => o.CostInvoice2TypeID == id);
                        if (costInvoice2Type == null)
                        {
                            notification = new Notification()
                            {
                                Type = NotificationType.Error, Message = "Can't Find Data"
                            };
                            return(false);
                        }
                    }
                    this.converter.DTO2DB_CostInvoice(costInvoice2TypeDto, ref costInvoice2Type);
                    context.SaveChanges();

                    dtoItem = this.GetData(costInvoice2Type.CostInvoice2TypeID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification()
                {
                    Type = NotificationType.Error, Message = ex.Message
                };

                return(false);
            }
        }
예제 #2
0
 public void DTO2DB_CostInvoice(DTO.CostInvoice2TypeDto dto, ref CostInvoice2Type db)
 {
     AutoMapper.Mapper.Map <DTO.CostInvoice2TypeDto, CostInvoice2Type>(dto, db);
 }