Ejemplo n.º 1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            DTO.QualityDocumentDTO dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.QualityDocumentDTO>();

            try
            {
                using (var context = CreatContex())
                {
                    QualityDocument dbItem;

                    if (id == 0)
                    {
                        dbItem = new QualityDocument();
                        context.QualityDocument.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.QualityDocument.Where(o => o.QualityDocumentID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "Data Not Found !";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_QualityDocument(dtoItems, ref dbItem);

                        //upload file
                        Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
                        string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\";
                        if (dtoItems.File_HasChange.HasValue && dtoItems.File_HasChange.Value)
                        {
                            dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoItems.File_NewFile, dtoItems.AttachedFile, dtoItems.FriendlyName);
                        }

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

                        //save
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.QualityDocumentID, 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(true);
        }
Ejemplo n.º 2
0
 public void DTO2DB_QualityDocument(DTO.QualityDocumentDTO dtoItem, ref QualityDocument dbItem)
 {
     AutoMapper.Mapper.Map <DTO.QualityDocumentDTO, QualityDocument>(dtoItem, dbItem);
     dbItem.IssuedDate  = dtoItem.IssuedDate.ConvertStringToDateTime();
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
 }