Example #1
0
        public override bool Reset(int id, ref DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    FactoryProformaInvoice dbItem = context.FactoryProformaInvoice.FirstOrDefault(o => o.FactoryProformaInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory proforma invoice not found!";
                        return(false);
                    }

                    dbItem.IsConfirmed   = null;
                    dbItem.ConfirmedBy   = null;
                    dbItem.ConfirmedDate = null;
                    context.SaveChanges();

                    dtoItem = GetData(dtoItem.UpdatedBy.Value, dbItem.FactoryProformaInvoiceID, 0, string.Empty, 0, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Example #2
0
        public bool DeleteData(int id, int userId, 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 (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    FactoryProformaInvoice dbItem = context.FactoryProformaInvoice.FirstOrDefault(o => o.FactoryProformaInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory proforma invoice not found!";
                        return(false);
                    }
                    else
                    {
                        // check if the proforma invoice has been approved
                        if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                        {
                            throw new Exception("Can not delete the confirmed proforma invoice!");
                        }

                        context.FactoryProformaInvoice.Remove(dbItem);
                        context.SaveChanges();

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

                return(false);
            }
        }
Example #3
0
        public override bool Approve(int id, ref DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    FactoryProformaInvoice dbItem = context.FactoryProformaInvoice.FirstOrDefault(o => o.FactoryProformaInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Factory proforma invoice not found!";
                        return(false);
                    }

                    // check if proforma invoice has attached file
                    if (string.IsNullOrEmpty(dbItem.AttachedFile))
                    {
                        throw new Exception("Attached scaned file is required in order to approve the proforma invoice!");
                    }

                    dbItem.IsConfirmed   = true;
                    dbItem.ConfirmedBy   = dtoItem.UpdatedBy;
                    dbItem.ConfirmedDate = DateTime.Now;
                    context.SaveChanges();

                    dtoItem = GetData(dtoItem.UpdatedBy.Value, dbItem.FactoryProformaInvoiceID, 0, string.Empty, 0, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Example #4
0
        public override bool UpdateData(int id, ref DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    FactoryProformaInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new FactoryProformaInvoice();
                        context.FactoryProformaInvoice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.FactoryProformaInvoice.FirstOrDefault(o => o.FactoryProformaInvoiceID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Factory proforma invoice not found!";
                        return(false);
                    }
                    else
                    {
                        // check if detail is valid
                        int factoryOrderID = dtoItem.FactoryOrderID.Value;
                        var dtoCheckInfo   = context.FactoryProformaInvoiceMng_FactoryOrderInfo_View.Where(o => o.FactoryOrderID == factoryOrderID).ToList();
                        foreach (DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail dtoDetail in dtoItem.Details)
                        {
                            if (dtoDetail.FactoryOrderDetailID.HasValue && dtoDetail.FactoryOrderDetailID > 0 && dtoCheckInfo.Count(o => o.FactoryOrderDetailID == dtoDetail.FactoryOrderDetailID.Value) == 0)
                            {
                                throw new Exception("Invalid detail: " + dtoDetail.ArticleCode + " not exists in factory order " + dtoItem.FactoryUD + " !");
                            }
                        }

                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        converter.DTO2BD(dtoItem, ref dbItem);
                        context.FactoryProformaInvoiceDetail.Local.Where(o => o.FactoryProformaInvoice == null).ToList().ForEach(o => context.FactoryProformaInvoiceDetail.Remove(o));
                        context.SaveChanges();

                        // processing file
                        if (dtoItem.AttachedFile_HasChange)
                        {
                            dbItem.AttachedFile = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.AttachedFile_NewFile, dtoItem.AttachedFile);
                        }
                        context.SaveChanges();

                        dtoItem = GetData(dtoItem.UpdatedBy.Value, dbItem.FactoryProformaInvoiceID, 0, string.Empty, 0, out notification).Data;

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

                return(false);
            }
        }