示例#1
0
 public void DTO2BD(DTO.OrganizationChart dtoItem, ref Organigram dbItem)
 {
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
     AutoMapper.Mapper.Map <DTO.OrganizationChart, Organigram>(dtoItem, dbItem);
 }
示例#2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.OrganizationChart dtoOrganizationChart = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OrganizationChart>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (OrganigramMngEntities context = CreateContext())
                {
                    Organigram dbItem = null;
                    if (id < 0)
                    {
                        dbItem = new Organigram();
                        context.Organigram.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Organigram.FirstOrDefault(o => o.OrganigramID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Organigram info not found!";
                        return(false);
                    }
                    else
                    {
                        //foreach(DTO.Employee )
                        converter.DTO2BD(dtoOrganizationChart, ref dbItem);


                        // processing image
                        if (dtoOrganizationChart.ImageFile_HasChange)
                        {
                            dbItem.ImageFile = fwFactory.CreateFilePointer(this._tempFolder, dtoOrganizationChart.ImageFile_NewFile, dtoOrganizationChart.ImageFile);
                        }
                        if (dtoOrganizationChart.WorkSpaceFile_HasChanged)
                        {
                            dbItem.WorkSpaceFile = fwFactory.CreateFilePointer(this._tempFolder, dtoOrganizationChart.WorkSpaceFile_NewFile, dtoOrganizationChart.WorkSpaceFile);
                        }

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();

                        dtoItem = GetData(dbItem.OrganigramID, out notification).Data;

                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
            //throw new NotImplementedException();
        }