コード例 #1
0
        public bool DeleteProgress(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SampleItemMngEntities context = CreateContext())
                {
                    // check if can delete
                    SampleProgress dbItem = context.SampleProgress.FirstOrDefault(o => o.SampleProgressID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Progress not found");
                    }

                    // everything ok, delete
                    // remove attached file
                    foreach (SampleProgressImage dbImage in dbItem.SampleProgressImage.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbImage.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbImage.FileUD);
                        }
                        dbItem.SampleProgressImage.Remove(dbImage);
                    }
                    context.SampleProgressImage.Local.Where(o => o.SampleProgress == null).ToList().ForEach(o => context.SampleProgressImage.Remove(o));
                    context.SampleProgress.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public bool DeleteAppointment(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (SCMAgendaMngEntities context = CreateContext())
                {
                    SCMAppointment dbItem = context.SCMAppointment.FirstOrDefault(o => o.SCMAppointmentID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Event not found!");
                    }
                    if (dbItem.MeetingLocationID.Value != 5 && dbItem.UserID.Value != userId)
                    {
                        throw new Exception("You can not delete this event, please contact the event owner!");
                    }

                    // delete the event
                    foreach (SCMAppointmentAttachedFile dbFile in dbItem.SCMAppointmentAttachedFile.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbFile.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbFile.FileUD);
                        }
                        dbItem.SCMAppointmentAttachedFile.Remove(dbFile);
                        context.SCMAppointmentAttachedFile.Remove(dbFile);
                    }
                    // delete the user
                    foreach (SCMAppointmentUser dbUser in dbItem.SCMAppointmentUser.ToArray())
                    {
                        dbItem.SCMAppointmentUser.Remove(dbUser);
                        context.SCMAppointmentUser.Remove(dbUser);
                    }
                    context.SCMAppointment.Remove(dbItem);
                    context.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #3
0
        public bool DeleteData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckPLCPermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected plc data");
                }

                using (FactoryPLCMngEntities context = CreateContext())
                {
                    // check if can delete PLC
                    string loadingPlanUD = context.FactoryPLCMng_function_CheckIfCanDeletePLC(id).FirstOrDefault();
                    if (!string.IsNullOrEmpty(loadingPlanUD))
                    {
                        throw new Exception("Current PLC already exists in loading plan: " + loadingPlanUD);
                    }

                    // everything ok, delete the plc
                    PLC dbItem = context.PLC.FirstOrDefault(o => o.PLCID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("PLC not found");
                    }

                    // remove image
                    foreach (PLCImage dbImage in dbItem.PLCImage)
                    {
                        if (!string.IsNullOrEmpty(dbImage.ImageFile))
                        {
                            fwFactory.RemoveImageFile(dbImage.ImageFile);
                        }
                    }
                    context.PLC.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
コード例 #4
0
        public bool DeleteData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckFactoryInvoicePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected invoice data");
                }

                using (FactoryInvoiceOtherMngEntities context = CreateContext())
                {
                    FactoryInvoice dbItem = context.FactoryInvoice.FirstOrDefault(o => o.FactoryInvoiceID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Invoice not found!");
                    }

                    // check if invoice already confirmed
                    if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                    {
                        throw new Exception("Can not delete the confirmed invoice!");
                    }

                    // everything ok, delete the invoice
                    if (dbItem.ScanFile != string.Empty)
                    {
                        fwFactory.RemoveImageFile(dbItem.ScanFile);
                    }
                    context.FactoryInvoice.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
コード例 #5
0
        public bool DeleteData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckFactoryProformaInvoicePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected proforma invoice data");
                }

                using (FactoryProformaInvoice2MngEntities context = CreateContext())
                {
                    // check if can delete
                    FactoryProformaInvoice2 dbItem = context.FactoryProformaInvoice2.FirstOrDefault(o => o.FactoryProformaInvoiceID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Factory proforma invoice not found");
                    }
                    if ((dbItem.IsFurnindoConfirmed.HasValue && dbItem.IsFurnindoConfirmed.Value) || (dbItem.IsFactoryConfirmed.HasValue && dbItem.IsFactoryConfirmed.Value))
                    {
                        throw new Exception("Can not delete the proforma invoice: it's already been confirmed by one party");
                    }

                    // everything ok, delete
                    // remove attached file
                    if (!string.IsNullOrEmpty(dbItem.AttachedFile))
                    {
                        fwFactory.RemoveImageFile(dbItem.AttachedFile);
                    }
                    context.FactoryProformaInvoice2.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
コード例 #6
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (var context = CreateContext())
                {
                    var dbItem = context.ClientComplaints.FirstOrDefault(o => o.ClientComplaintID == id);
                    if (dbItem == null)
                    {
                        return(true);
                    }

                    foreach (ClientComplaintItem dbComplaintItem in dbItem.ClientComplaintItems.ToArray())
                    {
                        foreach (ClientComplaintItemImage dbImage in dbComplaintItem.ClientComplaintItemImages.ToArray())
                        {
                            if (!string.IsNullOrEmpty(dbImage.ImageFile))
                            {
                                // remove image file
                                fwFactory.RemoveImageFile(dbImage.ImageFile);
                            }
                        }
                    }
                    context.ClientComplaints.Remove(dbItem);
                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);

                return(false);
            }
        }
コード例 #7
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.Factory dtoFactory = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Factory>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryMng2Entities context = CreateContext())
                {
                    Factory dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Factory();
                        context.Factory.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Factory.FirstOrDefault(o => o.FactoryID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFactory.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        // process image
                        foreach (DTO.FactoryImage dtoImage in dtoFactory.FactoryImages)
                        {
                            if (dtoImage.HasChange)
                            {
                                dtoImage.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoImage.NewFile, dtoImage.FileUD);
                            }
                        }

                        // Process business card image
                        foreach (DTO.FactoryBusinessCard dtoCard in dtoFactory.FactoryBusinessCard)
                        {
                            if (dtoCard.FrontHasChange)
                            {
                                dtoCard.FrontFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.FrontNewFile, dtoCard.FrontFileUD);
                            }

                            if (dtoCard.BehindHasChange)
                            {
                                dtoCard.BehindFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.BehindNewFile, dtoCard.BehindFileUD);
                            }
                        }

                        // processing certificate file
                        foreach (DTO.FactoryCertificate dtoCertificate in dtoFactory.FactoryCertificates)
                        {
                            if (dtoCertificate.CertificateFileHasChange)
                            {
                                if (string.IsNullOrEmpty(dtoCertificate.NewCertificateFile))
                                {
                                    fwFactory.RemoveImageFile(dtoCertificate.CertificateFile);
                                }
                                else
                                {
                                    dtoCertificate.CertificateFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCertificate.NewCertificateFile, dtoCertificate.CertificateFile);
                                }
                            }
                        }

                        // remove Technical Image
                        foreach (FactoryImage dbImage in context.FactoryImage.Local.Where(o => o.Factory == null).ToList())
                        {
                            if (!string.IsNullOrEmpty(dbImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbImage.FileUD);
                            }
                        }

                        // processing image
                        if (dtoFactory.LogoImage_HasChange)
                        {
                            dtoFactory.LogoImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactory.LogoImage_NewFile, dtoFactory.LogoImage);
                        }

                        if (dtoFactory.FactoryGalleries != null)
                        {
                            // Pre-event update FactoryGallery
                            foreach (DTO.FactoryGalleryDTO dtoFactoryGallery in dtoFactory.FactoryGalleries.Where(o => o.FactoryGalleryHasChange))
                            {
                                dtoFactoryGallery.FactoryGalleryUD = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoFactoryGallery.FactoryGalleryNewFile, dtoFactoryGallery.FactoryGalleryUD);
                            }
                        }

                        //foreach (DTO.FactoryDocumentDTO dtoDocumentFile in dtoFactory.factoryDocuments)
                        //{
                        //    if (dtoDocumentFile.FactoryDocumentHasChange)
                        //    {
                        //        if (string.IsNullOrEmpty(dtoDocumentFile.FactoryDocumentNewFile))
                        //        {
                        //            fwFactory.RemoveFile(dtoDocumentFile.FactoryDocumentFile);
                        //        }
                        //        else
                        //        {
                        //            dtoDocumentFile.FactoryDocumentFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoDocumentFile.FactoryDocumentNewFile, dtoDocumentFile.FactoryDocumentFile, dtoDocumentFile.FriendlyName);
                        //        }
                        //    }
                        //}

                        converter.DTO2BD(dtoFactory, ref dbItem, userId);

                        //
                        //remove orphan item
                        //

                        // FactoryImage
                        context.FactoryImage.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryImage.Remove(o));

                        // FactoryBusinessCard
                        context.FactoryBusinessCard.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryBusinessCard.Remove(o));

                        // FactoryDirector
                        context.FactoryDirector.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryDirector.Remove(o));

                        // FactoryManager
                        context.FactoryManager.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryManager.Remove(o));

                        // FactoryPricing
                        context.FactoryPricing.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryPricing.Remove(o));

                        // FactoryResponsiblePerson
                        context.FactoryResponsiblePerson.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryResponsiblePerson.Remove(o));

                        // SampleTechnical
                        context.FactorySampleTechnical.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactorySampleTechnical.Remove(o));

                        // FactorySupplier
                        //context.FactoryRawMaterialSupplier.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryRawMaterialSupplier.Remove(o));
                        context.FactorySupplier.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactorySupplier.Remove(o));

                        // FactoryInHouseTest
                        context.FactoryInHouseTest.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryInHouseTest.Remove(o));

                        // FactoryCertificate
                        context.FactoryCertificate.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryCertificate.Remove(o));

                        //FactoryCapacity By Weeks
                        context.FactoryCapacity.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryCapacity.Remove(o));

                        //FactoryContactQuickInfo
                        context.FactoryContactQuickInfo.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryContactQuickInfo.Remove(o));

                        //FactoryProductGroup
                        context.FactoryProductGroup.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryProductGroup.Remove(o));

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

                        // FactoryGallery for Factory(remove value Factory is null)
                        foreach (FactoryGallery dbFactoryGallery in context.FactoryGallery.Where(o => o.Factory == null).ToList())
                        {
                            fwFactory.RemoveImageFile(dbFactoryGallery.FactoryGalleryUD);
                            context.FactoryGallery.Remove(dbFactoryGallery);
                        }

                        context.SaveChanges();

                        //Update Permission Factory
                        if (id == 0)
                        {
                            context.Factory2Mng_function_AddFactoryPermissionNew(dbItem.FactoryID);
                            dtoItem = GetData(userId, dbItem.FactoryID, out notification).Data;
                        }
                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
コード例 #8
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.FactoryRawMaterial dtoFactoryRawMaterial = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryRawMaterial>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                //Get CompanyID
                int?companyID = fwFactory.GetCompanyID(userId);

                using (FactoryRawMaterialMngEntities context = CreateContext())
                {
                    FactoryRawMaterial dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryRawMaterial();
                        context.FactoryRawMaterial.Add(dbItem);
                        var checkUD = context.FactoryRawMaterial.ToList();

                        foreach (var item in checkUD)
                        {
                            if (item.FactoryRawMaterialUD == dtoFactoryRawMaterial.FactoryRawMaterialUD)
                            {
                                throw new Exception("Sub Supplier code exists !");
                            }
                        }
                    }
                    else
                    {
                        dbItem = context.FactoryRawMaterial.FirstOrDefault(o => o.FactoryRawMaterialID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory Raw Material not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFactoryRawMaterial.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        //file processing
                        Library.FileHelper.FileManager fileMng = new Library.FileHelper.FileManager(FrameworkSetting.Setting.AbsoluteFileFolder);
                        string fileNeedDeleted          = string.Empty;
                        string thumbnailFileNeedDeleted = string.Empty;

                        foreach (var contractItem in dtoFactoryRawMaterial.SubSupplierContracts.Where(o => o.ContractFileHasChange))
                        {
                            if (!string.IsNullOrEmpty(contractItem.ContractFile))
                            {
                                fwFactory.GetDBFileLocation(contractItem.ContractFile, out fileNeedDeleted, out thumbnailFileNeedDeleted);
                                if (!string.IsNullOrEmpty(fileNeedDeleted))
                                {
                                    try
                                    {
                                        fileMng.DeleteFile(fileNeedDeleted);
                                    }
                                    catch { }
                                }
                            }

                            if (string.IsNullOrEmpty(contractItem.NewContractFile))
                            {
                                // remove file registration in File table
                                fwFactory.RemoveFile(contractItem.ContractFile);

                                // reset file in table Contract
                                contractItem.ContractFile = string.Empty;
                            }
                            else
                            {
                                string outDBFileLocation = "";
                                string outFileFullPath   = "";
                                string outFilePointer    = "";
                                // copy new file
                                fileMng.StoreFile(this._tempFolder + contractItem.NewContractFile, out outDBFileLocation, out outFileFullPath);


                                if (File.Exists(outFileFullPath))
                                {
                                    FileInfo info = new FileInfo(outFileFullPath);

                                    // insert/update file registration in database
                                    fwFactory.UpdateFile(contractItem.ContractFile, contractItem.NewContractFile, outDBFileLocation, info.Extension, "", (int)info.Length, out outFilePointer);

                                    // set file database pointer
                                    contractItem.ContractFile = outFilePointer;
                                }
                            }
                        }

                        // processing certificate file
                        foreach (DTO.FactoryRawMaterialCertificate dtoCertificate in dtoFactoryRawMaterial.FactoryRawMaterialCertificates)
                        {
                            if (dtoCertificate.CertificateFileHasChange)
                            {
                                if (string.IsNullOrEmpty(dtoCertificate.NewCertificateFile))
                                {
                                    fwFactory.RemoveImageFile(dtoCertificate.CertificateFile);
                                }
                                else
                                {
                                    dtoCertificate.CertificateFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCertificate.NewCertificateFile, dtoCertificate.CertificateFile);
                                }
                            }
                        }
                        // Process business card image
                        foreach (DTO.FactoryRawMaterialBusinessCardDTO dtoCard in dtoFactoryRawMaterial.FactoryRawMaterialBusinessCardDTO)
                        {
                            if (dtoCard.FrontHasChange)
                            {
                                dtoCard.FrontFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.FrontNewFile, dtoCard.FrontFileUD);
                            }

                            if (dtoCard.BehindHasChange)
                            {
                                dtoCard.BehindFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.BehindNewFile, dtoCard.BehindFileUD);
                            }
                        }
                        // processing logo image
                        if (dtoFactoryRawMaterial.LogoFile_HasChange)
                        {
                            dtoFactoryRawMaterial.LogoFile = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactoryRawMaterial.LogoFile_NewFile, dtoFactoryRawMaterial.LogoFile);
                        }

                        // process image
                        foreach (DTO.FactoryRawMaterialImage dtoImage in dtoFactoryRawMaterial.FactoryRawMaterialImages)
                        {
                            if (dtoImage.HasChange)
                            {
                                dtoImage.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoImage.NewFile, dtoImage.FileUD);
                            }
                        }
                        if (dtoFactoryRawMaterial.FactoryRawMaterialGalleryDTO != null)
                        {
                            // Pre-event update FactoryGallery
                            foreach (DTO.FactoryRawMaterialGalleryDTO dtoFactoryGallery in dtoFactoryRawMaterial.FactoryRawMaterialGalleryDTO.Where(o => o.FactoryGalleryHasChange))
                            {
                                dtoFactoryGallery.FactoryRawMaterialGalleryUD = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoFactoryGallery.FactoryGalleryNewFile, dtoFactoryGallery.FactoryRawMaterialGalleryUD);
                            }
                        }
                        // remove Technical Image
                        foreach (FactoryRawMaterialImage dbImage in context.FactoryRawMaterialImage.Local.Where(o => o.FactoryRawMaterial == null).ToList())
                        {
                            if (!string.IsNullOrEmpty(dbImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbImage.FileUD);
                            }
                        }
                        //attach file
                        foreach (var item in dtoFactoryRawMaterial.materialsPrices.Where(o => o.AttachFileHasChange))
                        {
                            item.AttachFile = string.Empty;

                            string outDBFileLocation = "";
                            string outFileFullPath   = "";
                            string outFilePointer    = "";
                            // copy new file
                            fileMng.StoreFile(this._tempFolder + item.NewAttachFile, out outDBFileLocation, out outFileFullPath);


                            if (File.Exists(outFileFullPath))
                            {
                                FileInfo info = new FileInfo(outFileFullPath);

                                // insert/update file registration in database
                                fwFactory.UpdateFile(item.AttachFile, item.NewAttachFile, outDBFileLocation, info.Extension, "", (int)info.Length, out outFilePointer);

                                // set file database pointer
                                item.AttachFile = outFilePointer;
                            }
                        }
                        foreach (DTO.MaterialsPrice item in dtoFactoryRawMaterial.materialsPrices)
                        {
                            if (item.IsChange == true)
                            {
                                MaterialPriceHistory dbItemPriceHistory = new MaterialPriceHistory();
                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.Price            = (decimal)item.OldPrice;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;


                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.Qty         = (decimal)item.OldQty;
                                dbItemPriceHistory.UpdatedBy   = userId;
                                dbItemPriceHistory.UpdatedDate = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.StatusID         = (int)item.OldStatusID;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.ValidFrom        = Convert.ToDateTime(item.OldValidFrom);
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID  = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.AttachFileHistory = item.OldAttachFile;
                                dbItemPriceHistory.UpdatedBy         = userId;
                                dbItemPriceHistory.UpdatedDate       = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.RemarkHistory    = item.OldRemark;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;
                                context.MaterialPriceHistory.Add(dbItemPriceHistory);
                            }
                            else if (item.AttachFile != item.OldAttachFile)
                            {
                                MaterialPriceHistory dbItemPriceHistory = new MaterialPriceHistory();
                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.Price            = (decimal)item.OldPrice;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;


                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.Qty         = (decimal)item.OldQty;
                                dbItemPriceHistory.UpdatedBy   = userId;
                                dbItemPriceHistory.UpdatedDate = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.StatusID         = (int)item.OldStatusID;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.ValidFrom        = Convert.ToDateTime(item.OldValidFrom);
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID  = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.AttachFileHistory = item.OldAttachFile;
                                dbItemPriceHistory.UpdatedBy         = userId;
                                dbItemPriceHistory.UpdatedDate       = DateTime.Now;

                                dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID;
                                dbItemPriceHistory.RemarkHistory    = item.OldRemark;
                                dbItemPriceHistory.UpdatedBy        = userId;
                                dbItemPriceHistory.UpdatedDate      = DateTime.Now;
                                context.MaterialPriceHistory.Add(dbItemPriceHistory);
                            }
                        }

                        //convert dto to db
                        converter.DTO2BD(dtoFactoryRawMaterial, ref dbItem);
                        if (!string.IsNullOrEmpty(dbItem.WebAddress))
                        {
                            dbItem.WebAddress = dbItem.WebAddress.ToLower().Replace("http://", "").Replace("https://", "");
                        }

                        // FactoryRawMaterialCertificate
                        context.FactoryRawMaterialCertificate.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialCertificate.Remove(o));
                        // FactoryInHouseTest
                        context.FactoryRawMaterialTest.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialTest.Remove(o));
                        // FactoryRawMaterialPricingPerson
                        context.FactoryRawMaterialPricingPerson.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialPricingPerson.Remove(o));
                        // FactoryRawMaterialPricingPerson
                        context.FactoryRawMaterialQualityPerson.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialQualityPerson.Remove(o));
                        // FactoryRawMaterialPaymentTerm
                        context.FactoryRawMaterialPaymentTerm.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialPaymentTerm.Remove(o));

                        // FactoryRawMaterialMng_SupplierContactQuickInfo_View
                        context.SupplierContactQuickInfo.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierContactQuickInfo.Remove(o));

                        context.SupplierDirector.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierDirector.Remove(o));

                        context.SupplierManager.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierManager.Remove(o));

                        context.SupplierSampleTechnical.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierSampleTechnical.Remove(o));

                        context.MaterialsPrice.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.MaterialsPrice.Remove(o));

                        context.MaterialPriceHistory.Local.Where(o => o.MaterialsPrice == null).ToList().ForEach(o => context.MaterialPriceHistory.Remove(o));

                        context.FactoryRawMaterialBusinessCard.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialBusinessCard.Remove(o));

                        // FactoryGallery for Factory(remove value Factory is null)
                        foreach (FactoryRawMaterialGallery dbFactoryGallery in context.FactoryRawMaterialGallery.Where(o => o.FactoryRawMaterial == null).ToList())
                        {
                            fwFactory.RemoveImageFile(dbFactoryGallery.FactoryRawMaterialGalleryUD);
                            context.FactoryRawMaterialGallery.Remove(dbFactoryGallery);
                        }

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

                        context.SaveChanges();


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

                        return(true);
                    }
                }
            }

            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
コード例 #9
0
        public bool DeleteData(int userId, int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckLoadingPlanPermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected loading plan data");
                }

                using (FactoryLoadingPlanMngEntities context = CreateContext())
                {
                    LoadingPlan dbItem = context.LoadingPlan.FirstOrDefault(o => o.LoadingPlanID == id);
                    if (dbItem == null)
                    {
                        throw new Exception("Loading plan not found!");
                    }

                    // check if loading plan already confirmed
                    if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                    {
                        throw new Exception("Can not delete the confirmed loading plan!");
                    }

                    // check if loading plan already has invoice
                    PurchasingInvoice dbInvoice = context.PurchasingInvoice.FirstOrDefault(o => o.BookingID == dbItem.BookingID);
                    if (dbInvoice != null)
                    {
                        throw new Exception("Can not delete the loading plan which already has invoice issued!");
                    }

                    // everything ok, delete the loading plan
                    if (dbItem.ProductPicture1 != string.Empty)
                    {
                        fwFactory.RemoveImageFile(dbItem.ProductPicture1);
                    }
                    if (dbItem.ProductPicture2 != string.Empty)
                    {
                        fwFactory.RemoveImageFile(dbItem.ProductPicture2);
                    }
                    if (dbItem.ContainerPicture1 != string.Empty)
                    {
                        fwFactory.RemoveImageFile(dbItem.ContainerPicture1);
                    }
                    if (dbItem.ContainerPicture2 != string.Empty)
                    {
                        fwFactory.RemoveImageFile(dbItem.ContainerPicture2);
                    }
                    context.LoadingPlan.Remove(dbItem);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }

            return(true);
        }
コード例 #10
0
        public void DTO2DB_ProductBreakDownPAL2(DTO.ProductBreakDownPALData dtoItem, ref ProductBreakDownPAL dbItem, string tempFile, int userId)
        {
            AutoMapper.Mapper.Map <DTO.ProductBreakDownPALData, ProductBreakDownPAL>(dtoItem, dbItem);

            foreach (var dbCategory in dbItem.ProductBreakDownCategoryPAL.ToArray())
            {
                if (!dtoItem.ProductBreakDownCategoryPAL.Select(o => o.ProductBreakDownCategoryID).Contains(dbCategory.ProductBreakDownCategoryID))
                {
                    foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImagePAL.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbCategoryImage.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbCategoryImage.FileUD);
                        }

                        dbCategory.ProductBreakDownCategoryImagePAL.Remove(dbCategoryImage);
                    }

                    foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryTypePAL.ToArray())
                    {
                        foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                        {
                            dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                        }

                        dbCategory.ProductBreakDownCategoryTypePAL.Remove(dbCategoryType);
                    }

                    dbItem.ProductBreakDownCategoryPAL.Remove(dbCategory);
                }
            }

            foreach (var dtoCategory in dtoItem.ProductBreakDownCategoryPAL)
            {
                if (string.IsNullOrEmpty(dtoCategory.ProductBreakDownCategoryNM))
                {
                    continue;
                }

                if (dtoCategory.ProductBreakDownCalculationTypeID == 1 && dtoCategory.UnitPrice == 0)
                {
                    continue;
                }

                ProductBreakDownCategoryPAL dbCategory;

                if (dtoCategory.ProductBreakDownCategoryID < 0)
                {
                    dbCategory = new ProductBreakDownCategoryPAL();
                    dbItem.ProductBreakDownCategoryPAL.Add(dbCategory);
                }
                else
                {
                    dbCategory = dbItem.ProductBreakDownCategoryPAL.FirstOrDefault(o => o.ProductBreakDownCategoryID == dtoCategory.ProductBreakDownCategoryID);
                }

                if (dbCategory != null)
                {
                    AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryPALData, ProductBreakDownCategoryPAL>(dtoCategory, dbCategory);

                    foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImagePAL.ToArray())
                    {
                        if (!dtoCategory.ProductBreakDownCategoryImagePAL.Select(o => o.ProductBreakDownCategoryImageID).Contains(dbCategoryImage.ProductBreakDownCategoryImageID))
                        {
                            if (!string.IsNullOrEmpty(dbCategoryImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbCategoryImage.FileUD);
                            }
                            dbCategory.ProductBreakDownCategoryImagePAL.Remove(dbCategoryImage);
                        }
                    }

                    foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryTypePAL.ToArray())
                    {
                        if (!dtoCategory.ProductBreakDownCategoryTypePAL.Select(o => o.ProductBreakDownCategoryTypeID).Contains(dbCategoryType.ProductBreakDownCategoryTypeID))
                        {
                            foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                            {
                                dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                            }

                            dbCategory.ProductBreakDownCategoryTypePAL.Remove(dbCategoryType);
                        }
                    }

                    foreach (var dtoCategoryImage in dtoCategory.ProductBreakDownCategoryImagePAL)
                    {
                        ProductBreakDownCategoryImagePAL dbCategoryImage;

                        if (dtoCategoryImage.ProductBreakDownCategoryImageID < 0)
                        {
                            dbCategoryImage = new ProductBreakDownCategoryImagePAL();
                            dbCategory.ProductBreakDownCategoryImagePAL.Add(dbCategoryImage);
                        }
                        else
                        {
                            dbCategoryImage = dbCategory.ProductBreakDownCategoryImagePAL.FirstOrDefault(o => o.ProductBreakDownCategoryImageID == dtoCategoryImage.ProductBreakDownCategoryImageID);
                        }

                        if (dbCategoryImage != null)
                        {
                            if (dtoCategoryImage.HasChange.HasValue && dtoCategoryImage.HasChange.Value)
                            {
                                dbCategoryImage.FileUD = fwFactory.CreateFilePointer(tempFile, dtoCategoryImage.NewFile, dtoCategoryImage.FileUD, dtoCategoryImage.FriendlyName);
                            }

                            AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryImagePALData, ProductBreakDownCategoryImagePAL>(dtoCategoryImage, dbCategoryImage);
                        }
                    }

                    foreach (var dtoCategoryType in dtoCategory.ProductBreakDownCategoryTypePAL)
                    {
                        ProductBreakDownCategoryTypePAL dbCategoryType;

                        if (dtoCategoryType.ProductBreakDownCategoryTypeID < 0)
                        {
                            dbCategoryType = new ProductBreakDownCategoryTypePAL();
                            dbCategory.ProductBreakDownCategoryTypePAL.Add(dbCategoryType);
                        }
                        else
                        {
                            dbCategoryType = dbCategory.ProductBreakDownCategoryTypePAL.FirstOrDefault(o => o.ProductBreakDownCategoryTypeID == dtoCategoryType.ProductBreakDownCategoryTypeID);
                        }

                        if (dbCategoryType != null)
                        {
                            AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryTypePALData, ProductBreakDownCategoryTypePAL>(dtoCategoryType, dbCategoryType);

                            foreach (var dbDetail in dbCategoryType.ProductBreakDownDetailPAL.ToArray())
                            {
                                if (!dtoCategoryType.ProductBreakDownDetailPAL.Select(s => s.ProductBreakDownDetailID).Contains(dbDetail.ProductBreakDownDetailID))
                                {
                                    dbCategoryType.ProductBreakDownDetailPAL.Remove(dbDetail);
                                }
                            }

                            foreach (var dtoDetail in dtoCategoryType.ProductBreakDownDetailPAL)
                            {
                                ProductBreakDownDetailPAL dbDetail;

                                if (dtoDetail.ProductBreakDownDetailID <= 0)
                                {
                                    dbDetail = new ProductBreakDownDetailPAL();
                                    dbCategoryType.ProductBreakDownDetailPAL.Add(dbDetail);
                                }
                                else
                                {
                                    dbDetail = dbCategoryType.ProductBreakDownDetailPAL.FirstOrDefault(o => o.ProductBreakDownDetailID == dtoDetail.ProductBreakDownDetailID);
                                }

                                if (dbDetail != null)
                                {
                                    AutoMapper.Mapper.Map <DTO.ProductBreakDownDetailPALData, ProductBreakDownDetailPAL>(dtoDetail, dbDetail);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #11
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            CashBookData dataItem = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <CashBookData>();

            notification = new Notification()
            {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = CreateContext())
                {
                    CashBook dbItem;

                    if (id > 0)
                    {
                        dbItem = context.CashBook.FirstOrDefault(o => o.CashBookID == id);

                        if (dbItem == null)
                        {
                            notification.Type    = NotificationType.Error;
                            notification.Message = "Can not found data!";

                            return(false);
                        }
                    }
                    else
                    {
                        dbItem = context.CashBook.FirstOrDefault(o => o.CashBookUD == dataItem.CashBookUD);

                        if (dbItem != null)
                        {
                            notification.Type    = NotificationType.Error;
                            notification.Message = "CashBook receipt is exist in database!";

                            return(false);
                        }

                        DateTime bookDate = new DateTime();

                        if (!string.IsNullOrEmpty(dataItem.BookDate))
                        {
                            if (DateTime.TryParse(dataItem.BookDate, nl, System.Globalization.DateTimeStyles.None, out DateTime tmpDate))
                            {
                                bookDate = tmpDate;
                            }
                        }

                        var cashBalance = context.CashBookBalanceMng_CashBookBalance_View.OrderByDescending(o => o.UpdatedDate).FirstOrDefault();

                        if (!IsValidCreateCashBook(bookDate, cashBalance, out string messageError, out NotificationType typeError))
                        {
                            notification.Type    = typeError;
                            notification.Message = messageError;

                            return(false);
                        }

                        dbItem = new CashBook();
                        context.CashBook.Add(dbItem);
                    }

                    foreach (CashBookDocumentData item in dataItem.CashBookDocuments)
                    {
                        Module.Framework.DAL.DataFactory factory = new Framework.DAL.DataFactory();

                        if (item.HasChange)
                        {
                            if (string.IsNullOrEmpty(item.NewFile))
                            {
                                factory.RemoveImageFile(item.FileUD);
                            }
                            else
                            {
                                item.FileUD = factory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", item.NewFile, item.FileUD);
                            }
                        }
                    }

                    converter.DTO2DB_CashBook(dataItem, ref dbItem);
                    dbItem.UpdatedBy   = userId;
                    dbItem.UpdatedDate = DateTime.Now;

                    context.CashBookDocument.Local.Where(o => o.CashBook == null).ToList().ForEach(o => context.CashBookDocument.Remove(o));

                    context.SaveChanges();

                    dtoItem = converter.DB2DTO_CashBook(context.CashBookMng_CashBook_View.FirstOrDefault(o => o.CashBookID == dbItem.CashBookID));
                }

                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
コード例 #12
0
        public void DTO2DB_QualityInspection(DTO.QualityInspectionData dtoItem, ref QualityInspection dbItem, string templateFile, int userID)
        {
            Mapper.Map <DTO.QualityInspectionData, QualityInspection>(dtoItem, dbItem);

            dbItem.WorkCenterWorkingDate = dtoItem.WorkCenterWorkingDate.ConvertStringToDateTime();
            dbItem.InspectionDate        = dtoItem.InspectionDate.ConvertStringToDateTime();
            dbItem.ReceivedDate          = dtoItem.ReceivedDate.ConvertStringToDateTime();

            foreach (var dbItemCategory in dbItem.QualityInspectionCategory.ToArray())
            {
                if (!dtoItem.QualityInspectionCategories.Select(o => o.QualityInspectionCategoryID).Contains(dbItemCategory.QualityInspectionCategoryID))
                {
                    foreach (var dbItemCategoryImage in dbItemCategory.QualityInspectionCategoryImage.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbItemCategoryImage.FileUD))
                        {
                            fwFactory.RemoveImageFile(dbItemCategoryImage.FileUD);
                        }

                        dbItemCategory.QualityInspectionCategoryImage.Remove(dbItemCategoryImage);
                    }

                    dbItem.QualityInspectionCategory.Remove(dbItemCategory);
                }
            }

            foreach (var dtoItemCategory in dtoItem.QualityInspectionCategories)
            {
                QualityInspectionCategory dbItemCategory;

                if (dtoItemCategory.QualityInspectionCategoryID < 0)
                {
                    dbItemCategory = new QualityInspectionCategory();
                    dbItem.QualityInspectionCategory.Add(dbItemCategory);
                }
                else
                {
                    dbItemCategory = dbItem.QualityInspectionCategory.FirstOrDefault(o => o.QualityInspectionCategoryID == dtoItemCategory.QualityInspectionCategoryID);
                }

                if (dbItemCategory != null)
                {
                    Mapper.Map <DTO.QualityInspectionCategoryData, QualityInspectionCategory>(dtoItemCategory, dbItemCategory);

                    foreach (var dbItemCategoryImage in dbItemCategory.QualityInspectionCategoryImage.ToArray())
                    {
                        if (!dtoItemCategory.QualityInpsectionCategoryImages.Select(s => s.QualityInspectionCategoryImageID).Contains(dbItemCategoryImage.QualityInspectionCategoryImageID))
                        {
                            if (!string.IsNullOrEmpty(dbItemCategoryImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbItemCategoryImage.FileUD);
                            }

                            dbItemCategory.QualityInspectionCategoryImage.Remove(dbItemCategoryImage);
                        }
                    }

                    foreach (var dtoItemCategoryImage in dtoItemCategory.QualityInpsectionCategoryImages)
                    {
                        QualityInspectionCategoryImage dbItemCategoryImage;

                        if (dtoItemCategoryImage.QualityInspectionCategoryImageID < 0)
                        {
                            dbItemCategoryImage = new QualityInspectionCategoryImage();
                            dbItemCategory.QualityInspectionCategoryImage.Add(dbItemCategoryImage);
                        }
                        else
                        {
                            dbItemCategoryImage = dbItemCategory.QualityInspectionCategoryImage.FirstOrDefault(o => o.QualityInspectionCategoryImageID == dtoItemCategoryImage.QualityInspectionCategoryImageID);
                        }

                        if (dbItemCategoryImage != null)
                        {
                            Mapper.Map <DTO.QualityInspectionCategoryImageData, QualityInspectionCategoryImage>(dtoItemCategoryImage, dbItemCategoryImage);

                            if (dtoItemCategoryImage.HasChange.HasValue && dtoItemCategoryImage.HasChange.Value)
                            {
                                dbItemCategoryImage.FileUD = fwFactory.CreateFilePointer(templateFile, dtoItemCategoryImage.NewFile, dtoItemCategoryImage.FileUD, dtoItemCategoryImage.FriendlyName);
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
        public bool UpdateData(int userID, int id, ref object viewItem, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            DTO.BifaCompany dtoItem = ((Newtonsoft.Json.Linq.JObject)viewItem).ToObject <DTO.BifaCompany>();

            try
            {
                BifaCompany dbItem;

                using (var context = CreateContext())
                {
                    if (id == 0)
                    {
                        dbItem = new BifaCompany();
                        context.BifaCompany.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.BifaCompany.FirstOrDefault(o => o.BifaCompanyID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not find Bifa company!";

                        return(false);
                    }
                    else
                    {
                        // Process upload logo Bifa company
                        Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory();
                        if (dtoItem.Logo_HasChange)
                        {
                            if (string.IsNullOrEmpty(dtoItem.Logo_NewFile))
                            {
                                fwFactory.RemoveImageFile(dtoItem.Logo);
                            }
                            else
                            {
                                dtoItem.Logo = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userID.ToString() + @"\", dtoItem.Logo_NewFile, dtoItem.Logo);
                            }
                        }

                        converter.DTO2DB_BifaCompany(dtoItem, ref dbItem);
                        dbItem.UpdatedBy   = userID;
                        dbItem.UpdatedDate = System.DateTime.Now;

                        context.SaveChanges();

                        viewItem = GetData(dbItem.BifaCompanyID, out notification);

                        return(true);
                    }
                }
            }
            catch (System.Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Helper.GetInnerException(ex).Message;

                return(false);
            }
        }
コード例 #14
0
        public void DTO2DB_ClientComplaint(DTO.ClientComplaint dtoItem, ref ClientComplaint dbItem, int createdBy, string tempFolder)
        {
            // client complain items
            foreach (ClientComplaintItem dbComplaintItem in dbItem.ClientComplaintItems.ToArray())
            {
                if (!dtoItem.ClientComplaintItems.Select(o => o.ClientComplaintItemID).Contains(dbComplaintItem.ClientComplaintItemID))
                {
                    // remove image
                    foreach (ClientComplaintItemImage dbComplaintImage in dbComplaintItem.ClientComplaintItemImages.ToArray())
                    {
                        if (!string.IsNullOrEmpty(dbComplaintImage.ImageFile))
                        {
                            // remove image file
                            fwFactory.RemoveImageFile(dbComplaintImage.ImageFile);
                        }
                        dbComplaintItem.ClientComplaintItemImages.Remove(dbComplaintImage);
                    }
                    dbItem.ClientComplaintItems.Remove(dbComplaintItem);
                }
            }


            ////ClientComplaintItems
            //var willDeletedItems = new List<ClientComplaintItem>();
            //List<ClientComplaintItemImage> willDeletedItemImages;

            if (dtoItem.ClientComplaintItems != null && dtoItem.ClientComplaintItems.Count > 0)
            {
                ////CHECK
                //foreach (var dbComplaintItem in dbItem.ClientComplaintItems)
                //{
                //    //DB NOT EXIST IN DTO
                //    if (!dtoItem.ClientComplaintItems.Select(s => s.ClientComplaintItemID).Contains(dbComplaintItem.ClientComplaintItemID))
                //    {
                //        willDeletedItems.Add(dbComplaintItem);
                //    }
                //    else //DB IS EXIST IN DB
                //    {
                //        willDeletedItemImages = new List<ClientComplaintItemImage>();
                //        foreach (var dbComplaintItemImage in dbComplaintItem.ClientComplaintItemImages)
                //        {
                //            var clientComplaintItem = dtoItem.ClientComplaintItems
                //                .FirstOrDefault(o => o.ClientComplaintItemID == dbComplaintItem.ClientComplaintItemID);

                //            if (clientComplaintItem != null && !clientComplaintItem
                //                    .ClientComplaintItemImages.Select(x => x.ClientComplaintItemImageID)
                //                    .Contains(dbComplaintItemImage.ClientComplaintItemImageID))
                //            {
                //                willDeletedItemImages.Add(dbComplaintItemImage);
                //            }
                //        }

                //        foreach (var dbItemImage in willDeletedItemImages)
                //        {
                //            dbComplaintItem.ClientComplaintItemImages.Remove(dbItemImage);
                //        }
                //    }
                //}

                //// Delete Parent and child items
                //foreach (var dbParentItem in willDeletedItems)
                //{
                //    var deletedChildItems = dbParentItem.ClientComplaintItemImages.ToList();

                //    foreach (var item in deletedChildItems)
                //    {
                //        var clientComplaintItem = dbItem.ClientComplaintItems
                //            .FirstOrDefault(o => o.ClientComplaintItemID == dbParentItem.ClientComplaintItemID);

                //        if (clientComplaintItem != null)
                //            clientComplaintItem.ClientComplaintItemImages.Remove(item);
                //    }
                //    dbItem.ClientComplaintItems.Remove(dbParentItem);
                //}

                //MAP
                foreach (var dtoItemM in dtoItem.ClientComplaintItems)
                {
                    ClientComplaintItem      _dbItem;
                    ClientComplaintItemImage _dbItemImage;

                    if (dtoItemM.ClientComplaintItemID < 0)
                    {
                        _dbItem = new ClientComplaintItem();

                        if ((dtoItemM.ClientComplaintItemImages != null) && (dtoItemM.ClientComplaintItemImages.Count > 0))
                        {
                            foreach (var dtoItemImageM in dtoItemM.ClientComplaintItemImages)
                            {
                                // create new
                                if (dtoItemImageM.ImageFile_HasChange.HasValue && dtoItemImageM.ImageFile_HasChange.Value)
                                {
                                    dtoItemImageM.ImageFile = fwFactory.CreateFilePointer(tempFolder, dtoItemImageM.ImageFile_NewFile, dtoItemImageM.ImageFile);
                                }

                                _dbItemImage = new ClientComplaintItemImage();
                                _dbItem.ClientComplaintItemImages.Add(_dbItemImage);
                                AutoMapper.Mapper.Map <DTO.ClientComplaintItemImage, ClientComplaintItemImage>(dtoItemImageM, _dbItemImage);
                            }
                        }

                        dbItem.ClientComplaintItems.Add(_dbItem);
                    }
                    else
                    {
                        _dbItem = dbItem.ClientComplaintItems.FirstOrDefault(o => o.ClientComplaintItemID == dtoItemM.ClientComplaintItemID);

                        if (_dbItem != null &&
                            dtoItemM.ClientComplaintItemImages != null &&
                            dtoItemM.ClientComplaintItemImages.Count > 0)
                        {
                            foreach (var itemImage in dtoItemM.ClientComplaintItemImages)
                            {
                                //modify dto image field
                                if (itemImage.ImageFile_HasChange.HasValue && itemImage.ImageFile_HasChange.Value)
                                {
                                    itemImage.ImageFile = fwFactory.CreateFilePointer(tempFolder, itemImage.ImageFile_NewFile, itemImage.ImageFile);
                                }

                                if (itemImage.ClientComplaintItemImageID < 0)
                                {
                                    _dbItemImage = new ClientComplaintItemImage();
                                    _dbItem.ClientComplaintItemImages.Add(_dbItemImage);
                                }
                                else
                                {
                                    _dbItemImage = _dbItem.ClientComplaintItemImages
                                                   .FirstOrDefault(o => o.ClientComplaintItemImageID == itemImage.ClientComplaintItemImageID);
                                }

                                if (_dbItemImage != null)
                                {
                                    AutoMapper.Mapper.Map <DTO.ClientComplaintItemImage, ClientComplaintItemImage>(itemImage, _dbItemImage);
                                }
                            }
                        }
                    }

                    if (_dbItem != null)
                    {
                        AutoMapper.Mapper.Map <DTO.ClientComplaintItem, ClientComplaintItem>(dtoItemM, _dbItem);
                    }
                }
            }

            // ClientComplaintUsers
            if (dtoItem.ClientComplaintUsers != null && dtoItem.ClientComplaintUsers.Count > 0)
            {
                foreach (var item in dbItem.ClientComplaintUsers.ToArray())
                {
                    if (!dtoItem.ClientComplaintUsers.Select(o => o.ClientComplaintUserID).Contains(item.ClientComplaintUserID))
                    {
                        dbItem.ClientComplaintUsers.Remove(item);
                    }
                }

                //map child row
                foreach (var item in dtoItem.ClientComplaintUsers)
                {
                    ClientComplaintUser dbClientComplaintUser;
                    if (item.ClientComplaintUserID <= 0)
                    {
                        dbClientComplaintUser = new ClientComplaintUser();
                        dbItem.ClientComplaintUsers.Add(dbClientComplaintUser);
                    }
                    else
                    {
                        dbClientComplaintUser = dbItem.ClientComplaintUsers.FirstOrDefault(o => o.ClientComplaintUserID == item.ClientComplaintUserID);
                    }

                    if (dbClientComplaintUser != null)
                    {
                        Mapper.Map(item, dbClientComplaintUser);
                    }
                }
            }

            // ClientComplaintCommunications
            if (dtoItem.ClientComplaintCommunications != null && dtoItem.ClientComplaintCommunications.Count > 0)
            {
                foreach (var item in dbItem.ClientComplaintCommunications.ToArray())
                {
                    if (!dtoItem.ClientComplaintCommunications.Select(o => o.ClientComplaintCommunicationID).Contains(item.ClientComplaintCommunicationID))
                    {
                        dbItem.ClientComplaintCommunications.Remove(item);
                    }
                }

                //map child row
                foreach (var item in dtoItem.ClientComplaintCommunications)
                {
                    ClientComplaintCommunication dbClientComplaintCommunication;
                    if (item.ClientComplaintCommunicationID <= 0)
                    {
                        dbClientComplaintCommunication = new ClientComplaintCommunication();
                        dbItem.ClientComplaintCommunications.Add(dbClientComplaintCommunication);
                        dbClientComplaintCommunication.CreatedBy = createdBy;

                        if (DateTime.TryParse(item.CreatedDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate))
                        {
                            dbClientComplaintCommunication.CreatedDate = tmpDate;
                        }
                    }
                    else
                    {
                        dbClientComplaintCommunication = dbItem.ClientComplaintCommunications.FirstOrDefault(o => o.ClientComplaintCommunicationID == item.ClientComplaintCommunicationID);
                    }

                    if (dbClientComplaintCommunication != null)
                    {
                        Mapper.Map(item, dbClientComplaintCommunication);
                    }
                }
            }

            Mapper.Map(dtoItem, dbItem);
            dbItem.UpdatedDate        = DateTime.Now;
            dbItem.DeliveryDateClient = dtoItem.DeliveryDateClient.ConvertStringToDateTime();
        }
コード例 #15
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.QCReport dtoQCReport = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.QCReport>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (QCReportMngEntities context = CreateContext())
                {
                    QCReport dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new QCReport();
                        context.QCReport.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.QCReport.FirstOrDefault(o => o.QCReportID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "QC Report not found!";
                        return(false);
                    }
                    else
                    {
                        // process image
                        foreach (DTO.QCReportImage dtoImage in dtoQCReport.QCReportImages)
                        {
                            if (dtoImage.HasChange)
                            {
                                dtoImage.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoImage.NewFile, dtoImage.FileUD);
                            }
                        }

                        // process qc report document
                        foreach (DTO.QCReportDocument dtoDocument in dtoQCReport.QCReportDocuments)
                        {
                            if (dtoDocument.QCReportDocument_HasChange)
                            {
                                dtoDocument.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoDocument.QCReportDocument_NewFile, dtoDocument.FileUD);
                            }
                        }

                        // remove Technical Image
                        foreach (QCReportImage dbImage in context.QCReportImage.Local.Where(o => o.QCReport == null).ToList())
                        {
                            if (!string.IsNullOrEmpty(dbImage.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbImage.FileUD);
                            }
                        }

                        // remove Technical Document
                        foreach (QCReportDocument dbDocument in context.QCReportDocument.Local.Where(o => o.QCReport == null).ToList())
                        {
                            if (!string.IsNullOrEmpty(dbDocument.FileUD))
                            {
                                fwFactory.RemoveImageFile(dbDocument.FileUD);
                            }
                        }

                        context.QCReportImage.Local.Where(o => o.QCReport == null).ToList().ForEach(o => context.QCReportImage.Remove(o));
                        context.QCReportDocument.Local.Where(o => o.QCReport == null).ToList().ForEach(o => context.QCReportDocument.Remove(o));

                        //convert dto to db
                        converter.DTO2DB(dtoQCReport, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;

                        context.SaveChanges();
                        dtoItem = GetData(userId, dbItem.QCReportID, dbItem.FactoryOrderDetailID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
コード例 #16
0
        public void DTO2DB_BifaEvent(int userID, DTO.BifaEvent dtoItem, ref BifaEvent dbItem)
        {
            AutoMapper.Mapper.Map <DTO.BifaEvent, BifaEvent>(dtoItem, dbItem);

            dbItem.BifaCompanyID = dtoItem.BifaCompanyID;
            dbItem.BifaEventUD   = dtoItem.BifaEventUD;
            dbItem.StartDate     = dtoItem.StartDate.ConvertStringToDateTime();
            dbItem.EndDate       = dtoItem.EndDate.ConvertStringToDateTime();
            dbItem.UpdatedBy     = userID;
            dbItem.UpdatedDate   = System.DateTime.Now;

            if (dtoItem.BifaEventParticipants != null)
            {
                foreach (var item in dbItem.BifaEventParticipant.ToArray())
                {
                    if (!dtoItem.BifaEventParticipants.Select(s => s.BifaEventParticipantID).Contains(item.BifaEventParticipantID))
                    {
                        dbItem.BifaEventParticipant.Remove(item);
                    }
                }

                foreach (var item in dtoItem.BifaEventParticipants.ToArray())
                {
                    BifaEventParticipant dbItemDetail;

                    if (item.BifaEventParticipantID < 0)
                    {
                        dbItemDetail = new BifaEventParticipant();
                        dbItem.BifaEventParticipant.Add(dbItemDetail);
                    }
                    else
                    {
                        dbItemDetail = dbItem.BifaEventParticipant.FirstOrDefault(s => s.BifaEventParticipantID == item.BifaEventParticipantID);
                    }

                    if (dbItemDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.BifaEventParticipant, BifaEventParticipant>(item, dbItemDetail);

                        dbItemDetail.UpdatedBy   = userID;
                        dbItemDetail.UpdatedDate = System.DateTime.Now;
                    }
                }
            }

            if (dtoItem.BifaEventFiles != null)
            {
                Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory();

                foreach (var item in dbItem.BifaEventFile.ToList())
                {
                    if (!dtoItem.BifaEventFiles.Select(s => s.BifaEventFileID).Contains(item.BifaEventFileID))
                    {
                        dbItem.BifaEventFile.Remove(item);
                    }
                }

                foreach (var item in dtoItem.BifaEventFiles.ToList())
                {
                    BifaEventFile dbItemDetail;

                    if (item.BifaEventFileID < 0)
                    {
                        dbItemDetail = new BifaEventFile();
                        dbItem.BifaEventFile.Add(dbItemDetail);
                    }
                    else
                    {
                        dbItemDetail = dbItem.BifaEventFile.FirstOrDefault(s => s.BifaEventFileID == item.BifaEventFileID);
                    }

                    if (dbItemDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.BifaEventFile, BifaEventFile>(item, dbItemDetail);

                        if (item.HasChange)
                        {
                            if (string.IsNullOrEmpty(item.NewFile))
                            {
                                fwFactory.RemoveImageFile(item.FileUD);
                            }
                            else
                            {
                                dbItemDetail.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userID.ToString() + @"\", item.NewFile, item.FileUD);
                            }
                        }
                    }
                }
            }
        }