Esempio n. 1
0
        public bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.OutsourcingCostTypeDTO dtoOutSourcingCostType = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OutsourcingCostTypeDTO>();
            try
            {
                ////get companyID
                //Module.Framework.DAL.DataFactory fw_factory = new Framework.DAL.DataFactory();
                //int? companyID = fw_factory.GetCompanyID(userId);
                using (OutsourcingCostTypeMngEntities context = CreateContext())
                {
                    OutsourcingCostType dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new OutsourcingCostType();
                        context.OutsourcingCostType.Add(dbItem);
                        var listOutsourcingCostType = context.OutsourcingCostTypeMng_OutSourcingCostTypeMng_SearchView.ToList();
                        foreach (var item in listOutsourcingCostType)
                        {
                            if (dtoOutSourcingCostType.OutsourcingCostTypeUD == item.OutsourcingCostTypeUD)
                            {
                                notification.Message = "This code already exists. Please input another code!!";
                                notification.Type    = Library.DTO.NotificationType.Error;
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        dbItem = context.OutsourcingCostType.Where(o => o.OutsourcingCostTypeID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //
                        //convert dto to db
                        converter.DTO2DB_OutSourcingCostType(dtoOutSourcingCostType, ref dbItem);
                        //dbItem.CompanyID = companyID;
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;

                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.OutsourcingCostTypeID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Esempio n. 2
0
 public void DTO2DB_OutSourcingCostType(DTO.OutsourcingCostTypeDTO dtoItem, ref OutsourcingCostType dbItem)
 {
     AutoMapper.Mapper.Map <DTO.OutsourcingCostTypeDTO, OutsourcingCostType>(dtoItem, dbItem);
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
 }