コード例 #1
0
        public IHttpActionResult Update(int id, DTO.PLCMng.PLC dtoItem)
        {
            Library.DTO.Notification notification;

            // authentication
            Module.Framework.BLL fwBll = new Module.Framework.BLL();
            if (id > 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanUpdate))
            {
                // edit case
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }
            else if (id == 0 && !fwBll.CanPerformAction(ControllerContext.GetAuthUserId(), moduleCode, Library.DTO.ModuleAction.CanCreate))
            {
                // create new case
                return(InternalServerError(new Exception(Properties.Resources.NOT_AUTHORIZED)));
            }

            // validation
            if (!Helper.CommonHelper.ValidateDTO <DTO.PLCMng.PLC>(dtoItem, out notification))
            {
                return(Ok(new Library.DTO.ReturnData <DTO.PLCMng.PLC>()
                {
                    Data = dtoItem, Message = notification
                }));
            }

            // continue processing
            BLL.PLCMng bll = new BLL.PLCMng(Helper.AuthHelper.GetCurrentUserFolder(ControllerContext));
            bll.UpdateData(id, ref dtoItem, ControllerContext.GetAuthUserId(), out notification);
            return(Ok(new Library.DTO.ReturnData <DTO.PLCMng.PLC>()
            {
                Data = dtoItem, Message = notification
            }));
        }
コード例 #2
0
        public void DTO2DB(DTO.PLCMng.PLC dtoItem, string _tempFolder, ref PLC dbItem)
        {
            // map fields
            AutoMapper.Mapper.Map <DTO.PLCMng.PLC, PLC>(dtoItem, dbItem);

            // map images
            if (dtoItem.PLCImages != null)
            {
                // check for child rows deleted
                foreach (PLCImage dbImage in dbItem.PLCImage.ToArray())
                {
                    if (!dtoItem.PLCImages.Select(o => o.PLCImageID).Contains(dbImage.PLCImageID))
                    {
                        if (dbImage.ImageFile != string.Empty)
                        {
                            (new Module.Framework.DAL.DataFactory()).RemoveImageFile(dbImage.ImageFile);
                        }

                        dbItem.PLCImage.Remove(dbImage);
                    }
                }

                // map child rows
                foreach (DTO.PLCMng.PLCImage dtoImage in dtoItem.PLCImages)
                {
                    PLCImage dbImage;
                    if (dtoImage.PLCImageID <= 0)
                    {
                        dbImage = new PLCImage();
                        dbItem.PLCImage.Add(dbImage);
                    }
                    else
                    {
                        dbImage = dbItem.PLCImage.FirstOrDefault(o => o.PLCImageID == dtoImage.PLCImageID);
                    }

                    if (dbImage != null)
                    {
                        AutoMapper.Mapper.Map <DTO.PLCMng.PLCImage, PLCImage>(dtoImage, dbImage);
                        if (dtoImage.ImageFile_HasChange)
                        {
                            dbImage.ImageFile = (new Module.Framework.DAL.DataFactory()).CreateFilePointer(_tempFolder, dtoImage.ImageFile_NewFile, dtoImage.ImageFile);
                        }
                    }
                }
            }
        }