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

                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.OutsourcingCostID, 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);
            }
        }
 public void DTO2DB_OutSourcingCost(DTO.OutsourcingCostDTO dtoItem, ref OutsourcingCost dbItem)
 {
     AutoMapper.Mapper.Map <DTO.OutsourcingCostDTO, OutsourcingCost>(dtoItem, dbItem);
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
 }