Пример #1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (PurchaseRequestMngEntities context = CreateContext())
         {
             var dbItem = context.PurchaseRequest.Where(o => o.PurchaseRequestID == id).FirstOrDefault();
             context.PurchaseRequest.Remove(dbItem);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(false);
     }
 }
Пример #2
0
        public bool ApprovePrice(int userId, int purchaseRequestDetailID, int purchaseQuotationDetailID, decimal?approvedQnt, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "Approve price success !"
            };
            try
            {
                using (PurchaseRequestMngEntities context = CreateContext())
                {
                    if (!approvedQnt.HasValue || approvedQnt == 0)
                    {
                        throw new Exception("Please select quantity to approve");
                    }

                    var approvePrice = context.PurchaseRequestDetailApproval.Where(o => o.PurchaseRequestDetailID == purchaseRequestDetailID && o.PurchaseQuotationDetailID == purchaseQuotationDetailID).FirstOrDefault();
                    if (approvePrice != null)
                    {
                        throw new Exception("Request has been arppoved. You do not need approved again.");
                    }

                    PurchaseRequestDetailApproval dbApproval = new PurchaseRequestDetailApproval();
                    dbApproval.PurchaseRequestDetailID   = purchaseRequestDetailID;
                    dbApproval.PurchaseQuotationDetailID = purchaseQuotationDetailID;
                    dbApproval.ApprovedQnt  = approvedQnt;
                    dbApproval.ApprovedBy   = userId;
                    dbApproval.ApprovedDate = DateTime.Now;
                    context.PurchaseRequestDetailApproval.Add(dbApproval);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Пример #3
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.PurchaseRequestDTO dtoPurchaseRequest = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseRequestDTO>();
            try
            {
                //get companyID
                Module.Framework.DAL.DataFactory fw_factory = new Framework.DAL.DataFactory();
                int?companyID = fw_factory.GetCompanyID(userId);
                using (PurchaseRequestMngEntities context = CreateContext())
                {
                    PurchaseRequest dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new PurchaseRequest();
                        context.PurchaseRequest.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.PurchaseRequest.Where(o => o.PurchaseRequestID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2DB_PurchaseRequest(dtoPurchaseRequest, ref dbItem);
                        dbItem.CompanyID   = companyID;
                        dbItem.UpdatedBy   = userId;
                        dbItem.UpdatedDate = DateTime.Now;

                        if (id == 0)
                        {
                            dbItem.PurchaseRequestUD = context.PurchaseRequestMng_function_GeneratePurchaseRequestUD().FirstOrDefault();
                            dbItem.CreatedBy         = userId;
                            dbItem.CreatedDate       = DateTime.Now;
                        }

                        //remove orphan
                        context.PurchaseRequestWorkOrderDetail.Local.Where(o => o.PurchaseRequestDetail == null).ToList().ForEach(o => context.PurchaseRequestWorkOrderDetail.Remove(o));
                        context.PurchaseRequestDetail.Local.Where(o => o.PurchaseRequest == null).ToList().ForEach(o => context.PurchaseRequestDetail.Remove(o));
                        //save data
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.PurchaseRequestID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }