예제 #1
0
        public void TestOrderAPI_ApproveOrder_ShouldReturnOrderStatusEqualToApprove()
        {
            Response = orderService.Approve(user, orderVMLight);
            OrderViewModelLight result = Response.Model as OrderViewModelLight;

            Assert.That(result.OrderStatusTypeId, Is.EqualTo(4));
        }
예제 #2
0
        public void TestOrderService_AdjustOrderItems_ShouldUpdatedOrderItemsQuantity(bool isAdd)
        {
            long _orderId = this.db.Context.Orders.OrderByDescending(o => o.OrderId).Select(o => o.OrderId).FirstOrDefault();

            List <OrderItem> orderItems = this.db.Context.OrderItems.Where(oi => oi.OrderId == _orderId).ToList();
            int orderItemsCount         = orderItems.Count();

            OrderViewModelLight model = orderService.GetOrderModel(_orderId).Model as OrderViewModelLight;

            if (isAdd)
            {
                OrderItem newOrderItem = orderItems.Last();
                orderItems.Add(newOrderItem);
                orderService.AdjustOrderItems(user, model, orderItems, isAdd, null);
                orderItems = this.db.Context.OrderItems.Where(oi => oi.OrderId == model.OrderId).ToList();
                Assert.That(orderItems.Count(), Is.GreaterThanOrEqualTo(orderItemsCount));
            }
            else
            {
                OrderItem orderItem = orderItems.First();
                orderItem.Quantity = 10;
                orderService.AdjustOrderItems(user, model, orderItems, isAdd, null);
                orderItems = this.db.Context.OrderItems.Where(oi => oi.OrderId == model.OrderId).ToList();
                Assert.That(orderItems.First().Quantity, Is.EqualTo(10));
            }
        }
예제 #3
0
        public ServiceResponse UpdateOrderStatus([FromUri] Int32 orderId, int orderStatus)
        {
#pragma warning disable CS0472 // The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
            if (orderId == null)
#pragma warning restore CS0472 // The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
            {
                response.Messages.AddError("OrderId is null");
            }
#pragma warning disable CS0472 // The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
            if (orderStatus == null)
#pragma warning restore CS0472 // The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'
            {
                response.Messages.AddError("OrderStatus is null");
            }

            if (response.HasError)
            {
                return(response);
            }
            else
            {
                OrderViewModelLight orderVMLight = orderService.GetOrderModel(orderId).Model as OrderViewModelLight;
                this.response = orderService.ChangeStatus(this.CurrentUser, orderVMLight, (OrderStatusTypeEnum)orderStatus);
            }
            return(response);
        }
예제 #4
0
        public void TestOrderAPI_RejectOrder_ShouldReturnOrderStatusEqualsToReject()
        {
            Response = orderService.Reject(user, orderVMLight);
            OrderViewModelLight result = Response.Model as OrderViewModelLight;

            Assert.That(result.OrderStatusTypeId, Is.EqualTo(8));
        }
        public ServiceResponse GetSubmittedOrder(UserSessionModel user, long quoteId)
        {
            var queryExistedOrder = from order in this.Context.Orders
                                    where order.QuoteId == quoteId
                                    select order;

            var existedOrder = queryExistedOrder.FirstOrDefault();

            if (existedOrder != null) // view
            {
                var query = from order in this.Context.Orders
                            join quote in this.Context.Quotes on order.QuoteId equals quote.QuoteId
                            join project in this.Context.Projects on quote.ProjectId equals project.ProjectId
                            join attachment in this.Context.OrderAttachments on order.OrderId equals attachment.OrderId
                            where order.QuoteId == quoteId
                            select new OrderViewModelLight
                {
                    OrderId           = order.OrderId,
                    ProjectId         = project.ProjectId,
                    ProjectName       = project.Name,
                    QuoteId           = quote.QuoteId,
                    DiscountRequestId = quote.DiscountRequestId,
                    QuoteTitle        = quote.Title,
                    BusinessId        = project.Owner.BusinessId,
                    //ERPAccountId = project.Owner.Business.ERPAccountId,
                    ShipToAddressId = project.ShipToAddressId,
                    PricingTypeId   = quote.IsCommission ? (byte)2 : (byte)1,
                    TotalNetPrice   = quote.TotalNet,
                    //TotalDiscountPercent = quote.DiscountPercentage,
                    TotalDiscountPercent        = quote.ApprovedDiscountPercentage,
                    Comments                    = order.Comments,
                    EstimatedDeliveryDate       = project.EstimatedDelivery,
                    OrderReleaseDate            = order.OrderReleaseDate,
                    PONumber                    = order.PONumber,
                    DeliveryAppointmentRequired = order.DeliveryAppointmentRequired,
                    DeliveryContactName         = order.DeliveryContactName,
                    DeliveryContactPhone        = order.DeliveryContactPhone,
                    SubmitDate                  = DateTime.Now,
                    SubmittedByUserId           = user.UserId,
                    SubmittedByUserName         = user.LastName + ", " + user.FirstName,
                    CreatedByUserId             = user.UserId,
                    UpdatedByUserId             = user.UserId,
                    ProjectDate                 = project.ProjectDate,
                    POAttachmentFileName        = attachment.FileName,
                    OrderStatusTypeId           = (OrderStatusTypeEnum)order.OrderStatusTypeId,
                    RequestedDiscountPercentage = (!string.IsNullOrEmpty(quote.DiscountRequests.FirstOrDefault().RequestedDiscount.ToString())) ?
                                                  quote.DiscountRequests.FirstOrDefault().RequestedDiscount : 0,
                    ApprovedDiscountPercentage = (quote.DiscountRequests.FirstOrDefault().ApprovedDiscount != null) ?
                                                 quote.DiscountRequests.FirstOrDefault().ApprovedDiscount.Value : 0,
                    Timestamp = quote.Timestamp
                };
                OrderViewModelLight model = query.FirstOrDefault();
                model.EstimatedReleaseDate = model.EstimatedDeliveryDate.AddDays(-10);
                model.Project = projectService.GetProjectModel(user, model.ProjectId).Model as ProjectModel;

                this.Response.Model = model;
            }

            return(this.Response);
        }
예제 #6
0
 public ServiceResponse RejectOrder(OrderViewModelLight orderVMLight)
 {
     this.ServiceResponse = _orderServices.Reject(this.CurrentUser, orderVMLight);
     if (this.ServiceResponse.IsOK)
     {
     }
     return(this.ServiceResponse);
 }
예제 #7
0
        public void TestOrderService_SubmitOrder_ShouldPerformModelValidation()
        {
            this.response.Messages.Items.Clear();
            this.response.Messages.HasErrors = false;

            OrderViewModelLight orderVMLight = new OrderViewModelLight();

            response = orderService.PostModel(user, orderVMLight);

            Assert.That(response.Messages.HasErrors, Is.EqualTo(true));

            if (orderVMLight.ERPAccountId == null)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelBusiness.BM010), Is.EqualTo(true));
            }

            if (orderVMLight.CurrentUser == null)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelUser.MU024), Is.EqualTo(true));
            }
            else if (orderVMLight.CurrentUser.Email == null)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelProject.MP124), Is.EqualTo(true));
            }

            if (orderVMLight.CurrentUser != null && !orderVMLight.CurrentUser.ShowPrices)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelBusiness.BM008), Is.EqualTo(true));
            }

            if (orderVMLight.POAttachmentFileName == null || orderVMLight.POAttachmentFileName == string.Empty)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceUI.POAttachmentRequired), Is.EqualTo(true));
            }

            if (orderVMLight.OrderReleaseDate == null || orderVMLight.OrderReleaseDate == DateTime.MinValue)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelProject.MP133), Is.EqualTo(true));
            }

            if (orderVMLight.OrderReleaseDate < orderVMLight.SubmitDate)
            {
                Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelProject.MP134), Is.EqualTo(true));
            }

            if (orderVMLight.DeliveryAppointmentRequired)
            {
                if (orderVMLight.DeliveryContactName == null || orderVMLight.DeliveryContactName.Length == 0)
                {
                    Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelProject.MP139), Is.EqualTo(true));
                }

                if (orderVMLight.DeliveryContactPhone == null || orderVMLight.DeliveryContactPhone.Length == 0)
                {
                    Assert.That(response.Messages.Items.Any(m => m.Text == Resources.ResourceModelProject.MP138), Is.EqualTo(true));
                }
            }
        }
예제 #8
0
        public ServiceResponse ApproveOrder(OrderViewModelLight orderVMLight)
        {
            this.ServiceResponse = _orderServices.Approve(this.CurrentUser, orderVMLight);
            if (this.ServiceResponse.IsOK)
            {
                var OrderForEmail = this.ServiceResponse.Model as OrderViewModelLight;
            }

            return(this.ServiceResponse);
        }
예제 #9
0
        public void TestOrderService_GetEntity_ShouldReturnOrderEntity()
        {
            long _orderId             = this.db.Context.Orders.OrderByDescending(o => o.OrderId).Select(o => o.OrderId).FirstOrDefault();
            OrderViewModelLight model = orderService.GetOrderModel(_orderId).Model as OrderViewModelLight;
            var result = orderService.GetEntity(user, model);

            Assert.That(result, Is.Not.EqualTo(null));
            Assert.IsInstanceOf <Order>(result);
            Assert.That(result.OrderId, Is.EqualTo(model.OrderId));
        }
예제 #10
0
        public ActionResult Orders()
        {
            ServiceResponse     response = new ServiceResponse();
            OrderViewModelLight model    = new OrderViewModelLight();

            //this.ServiceResponse.Model = new OrderViewModelLight();
            this.RouteData.Values["action"] = "Orders";

            return(View("Orders", model));
        }
예제 #11
0
        public void TestOrderService_ChangeOrderStatus_ShouldChangeOrderStatusPerRequest(int OrderStatusTypeId)
        {
            long _orderId             = this.db.Context.Orders.OrderByDescending(o => o.OrderId).Select(o => o.OrderId).FirstOrDefault();
            OrderViewModelLight model = orderService.GetOrderModel(_orderId).Model as OrderViewModelLight;
            var result = orderService.ChangeOrderStatus(user, model, (OrderStatusTypeEnum)OrderStatusTypeId);

            Assert.That(result.IsOK, Is.EqualTo(true));
            Order order = this.db.Context.Orders.Where(o => o.OrderId == model.OrderId).FirstOrDefault();

            Assert.That(order.OrderStatusTypeId, Is.EqualTo(OrderStatusTypeId));
        }
예제 #12
0
        public void TestOrderService_Delete_ShouldReturnOrderStatusAsCanceled()
        {
            long _orderId             = this.db.Context.Orders.Where(o => o.OrderStatusTypeId != 4).OrderByDescending(o => o.OrderId).Select(o => o.OrderId).FirstOrDefault();
            OrderViewModelLight model = orderService.GetOrderModel(_orderId).Model as OrderViewModelLight;
            var result = orderService.Delete(user, model);

            Assert.That(result.IsOK, Is.EqualTo(true));
            Order order = this.db.Context.Orders.Where(o => o.OrderId == model.OrderId).FirstOrDefault();

            Assert.That(order.OrderStatusTypeId, Is.EqualTo(8));
        }
예제 #13
0
        public ActionResult OrderReject(OrderViewModelLight model)
        {
            this.ServiceResponse       = orderService.Reject(this.CurrentUser, model);
            this.ShowKeyMessagesOnPage = true;

            if (ProcessServiceResponse(this.ServiceResponse))
            {
                SendApprovalRejectionEmail(this.ServiceResponse.Model as OrderViewModelLight);
                return(RedirectToAction("Orders", "UserDashboard"));
            }

            return(View("OrderForm", this.ServiceResponse.Model));
        }
예제 #14
0
        public TestOrderController()
        {
            orderService      = new OrderServices(this.TContext);
            orderServiceLight = new OrderServiceLight();
            searchOrders      = new SearchOrders();

            accountService = new AccountServices();
            user           = accountService.GetUserSessionModel("*****@*****.**").Model as UserSessionModel;
            quoteService   = new QuoteServices();

            orderVMLight                             = new OrderViewModelLight();
            orderVMLight.BusinessId                  = 206680765352640513;
            orderVMLight.ShipToAddressId             = 479102086194151432;
            orderVMLight.PricingTypeId               = 1;
            orderVMLight.PONumber                    = "AAPO0613201601";
            orderVMLight.TotalDiscountPercent        = 0;
            orderVMLight.EstimatedReleaseDate        = Convert.ToDateTime("2016-06-06 00:00:00.000");
            orderVMLight.DeliveryAppointmentRequired = false;
            orderVMLight.DeliveryContactName         = "";
            orderVMLight.DeliveryContactPhone        = "";
            orderVMLight.OrderReleaseDate            = DateTime.Now.AddDays(2);
            orderVMLight.SubmittedByUserId           = 392643416367824896;
            orderVMLight.SubmitDate                  = DateTime.Now;
            orderVMLight.CreatedByUserId             = 392643416367824896;
            orderVMLight.UpdatedByUserId             = 392643416367824896;
            orderVMLight.DiscountRequestId           = 0;
            orderVMLight.CommissionRequestId         = 0;
            orderVMLight.ERPOrderNumber              = "";
            orderVMLight.ERPPOKey                    = 0;
            orderVMLight.ERPStatus                   = "Submitted";
            orderVMLight.Comments                    = "PLEASE CALL BEFORE SHIPPING";
            orderVMLight.ERPComments                 = "";
            orderVMLight.ERPOrderDate                = null;
            orderVMLight.ERPInvoiceDate              = null;
            orderVMLight.ERPShipDate                 = null;
            orderVMLight.ERPInvoiceNumber            = null;
            orderVMLight.QuoteId                     = 479102111284477952;
            orderVMLight.ProjectId                   = 479102086194151424;
            orderVMLight.CurrentUser                 = user;
            var fileUpload = new FileUploadTest();

            orderVMLight.POAttachment         = fileUpload;
            orderVMLight.POAttachmentFileName = fileUpload.FileUploadName;
            orderVMLight.ERPAccountId         = "1234";

            orderControllerApi          = new OrderController();
            orderController             = new DPO.Web.Controllers.ProjectDashboardController();
            orderController.CurrentUser = user;

            projects = this.db.Projects.Where(p => p.OwnerId == user.UserId).ToList();
        }
예제 #15
0
        public void TestOrderService_GetOrderModelByOrderViewModelLight_ShouldReturnOrderViewModelLight()
        {
            orderVMLight.OrderId = this.db.Context.Orders.OrderByDescending(o => o.OrderId).Select(o => o.OrderId).FirstOrDefault();
            var result = orderService.GetOrderModel(user, orderVMLight);

            Assert.That(result.IsOK, Is.EqualTo(true));
            Assert.That(result, Is.Not.EqualTo(null));
            Assert.IsInstanceOf <OrderViewModelLight>(result.Model);
            OrderViewModelLight model = result.Model as OrderViewModelLight;

            Assert.That(model.OrderId, Is.EqualTo(orderVMLight.OrderId));

            orderVMLight.OrderId = 0;
        }
예제 #16
0
        public ActionResult OrderDelete(OrderViewModelLight model)
        {
            this.ServiceResponse       = orderService.Delete(this.CurrentUser, model);
            this.ShowKeyMessagesOnPage = true;

            if (ProcessServiceResponse(this.ServiceResponse))
            {
                //force email to be sent to user
                var OrderForEmail = this.ServiceResponse.Model as OrderViewModelLight;
                SendApprovalRejectionEmail(OrderForEmail);

                //return RedirectToAction("Quote", new QuoteModel { ProjectId = model.ProjectId, QuoteId = model.QuoteId });
                string url = "/v2/#/quote/" + model.QuoteId + "/existingRecord";
                return(Redirect(url));
            }

            return(View("OrderForm", this.ServiceResponse.Model));
        }
        public void InsertProjectInfoToMapics(OrderViewModelLight model)
        {
            var project = new ProjectInfo
            {
                BusinessId   = model.BusinessId.GetValueOrDefault(),
                BusinessName = model.BusinessName,
                ERPAccountId = !string.IsNullOrEmpty(model.ERPAccountId) ?
                               Convert.ToInt32(model.ERPAccountId) : 0,
                ProjectId   = model.ProjectId,
                ProjectName = model.ProjectName,
                AccountId   = model.AccountID,
                QuoteId     = model.QuoteId
            };

            var erpClient = new ERPClient();

            erpClient.PostProjectsInfoToMapicsAsync(project);
        }
예제 #18
0
        public void TestOrderService_GetOrderModelByQuoteId_ShouldReeturnOrderViewModelLight()
        {
            //Arrange
            this.response.Messages.Items.Clear();
            this.response.Messages.HasErrors = false;

            long quoteId = 479102111284477952;
            long orderId = 479113661118431232;

            OrderViewModelLight orderVMLight = new OrderViewModelLight();

            orderVMLight.QuoteId = quoteId;
            orderVMLight.OrderId = orderId;
            //Act
            response = orderService.GetOrderModel(user, orderVMLight);

            //Response
            Assert.That(response.IsOK, Is.EqualTo(true));
        }
        public Order GetEntity(UserSessionModel user, OrderViewModelLight model)
        {
            Order entity = null;

            if (!string.IsNullOrEmpty(model.OrderId.ToString()) && model.OrderId != 0)
            {
                entity = this.Db.QueryOrdersViewableByUser(user).FirstOrDefault(o => o.OrderId == model.OrderId);
            }
            else
            {
                entity = Db.OrderCreate(model.ProjectId, model.QuoteId);
            }

            if (entity == null)
            {
                this.Response.Messages.AddError(Resources.ResourceModelProject.MP004);
            }

            return(entity);
        }
예제 #20
0
        public ServiceResponse PostOrder(OrderViewModelLight model)
        {
            if (model.CurrentUser == null)
            {
                model.CurrentUser = this.CurrentUser;
            }

            if (model.CreatedByUserId == 0)
            {
                model.CreatedByUserId = model.CurrentUser.UserId;
            }

            if (model.UpdatedByUserId == 0)
            {
                model.UpdatedByUserId = model.CurrentUser.UserId;
            }

            var discountRequestVM = new DiscountRequestModel();

            using (var discountRequestService = new DiscountRequestServices())
            {
                this.ServiceResponse = discountRequestService.GetDiscountRequestModel(this.CurrentUser, model.ProjectId, model.QuoteId);
                discountRequestVM    = ServiceResponse.Model as DiscountRequestModel;
            }

            if (model.ERPAccountId != null)
            {
                ServiceResponse = _erpSvcProvider.CheckPONumberExist(model.ERPAccountId, model.PONumber);
            }
            else
            {
                ServiceResponse.Messages.AddError(Resources.ResourceModelBusiness.BM010);
            }

            if (ServiceResponse.IsOK)
            {
                ServiceResponse = _orderServices.PostModel(this.CurrentUser, model);
            }

            return(ServiceResponse);
        }
예제 #21
0
        public ServiceResponse UpdateOrderStatus(OrderViewModelLight orderVMLight)
        {
            if (orderVMLight.OrderId == 0)
            {
                this.ServiceResponse.Messages.AddError("OrderId is Invalid");
            }
            if (orderVMLight.OrderStatusTypeId == 0)
            {
                this.ServiceResponse.Messages.AddError("OrderStatus is Invalid");
            }

            if (this.ServiceResponse.HasError)
            {
                return(this.ServiceResponse);
            }
            else
            {
                var order = _orderServices.GetOrderModel(orderVMLight.OrderId).Model as OrderViewModelLight;
                using (var accountService = new AccountServices())
                {
                    var user = accountService.GetUserSessionModel(206016535569891328).Model as UserSessionModel;

                    if (user != null)
                    {
                        try
                        {
                            this.ServiceResponse = _orderServices.ChangeOrderStatus(user, order, (OrderStatusTypeEnum)orderVMLight.OrderStatusTypeId);
                        }
                        catch (Exception ex)
                        {
                            this.ServiceResponse.Messages.AddError(ex.Message);
                        }
                    }
                }
            }

            return(this.ServiceResponse);
        }
        public DPO.Model.Light.OrderSendEmailModel getOrderSendEmailModel(OrderViewModelLight orderVMLight)
        {
            var proj     = this.Db.GetProjectOwnerAndBusiness(orderVMLight.ProjectId);
            var business = this.Db.GetBusinessByProjectOwner(orderVMLight.ProjectId);

            orderVMLight.ProjectOwner = proj.Owner.FirstName + " " + proj.Owner.LastName;
            orderVMLight.BusinessName = business.BusinessName;

            //hacking code for ERP Invoice Date and ERP Order Date.will need to discuss about these to know when we can get these two values
            if (orderVMLight.ERPOrderDate == null)
            {
                orderVMLight.ERPOrderDate = DateTime.Now;
            }
            else
            {
                if (orderVMLight.ERPOrderDate == DateTime.MinValue)
                {
                    orderVMLight.ERPOrderDate = DateTime.Now;
                }
            }

            if (orderVMLight.ERPInvoiceDate == null)
            {
                orderVMLight.ERPInvoiceDate = DateTime.Now;
            }

            return(new DPO.Model.Light.OrderSendEmailModel
            {
                order = orderVMLight,
                AccountManagerEmail = business.AccountManagerEmail,
                AccountOwnerEmail = business.AccountOwnerEmail,
                RequestDiscountPercent = orderVMLight.RequestedDiscountPercentage,
                ApprovedDiscountPercent = orderVMLight.ApprovedDiscountPercentage,
                DARAttachmentFile = (orderVMLight.DiscountRequestId != null) ? orderVMLight.DARAttachmentFileName : null,
                COMAttachmentFile = (orderVMLight.CommissionRequestId != null) ? orderVMLight.COMAttachmentFileName : null
            });
        }
예제 #23
0
        public TestOrderAPI()
        {
            orderService      = new OrderServices(this.TContext);
            orderServiceLight = new OrderServiceLight();
            searchOrders      = new SearchOrders();

            accountService = new AccountServices();
            user           = accountService.GetUserSessionModel("*****@*****.**").Model as UserSessionModel;
            quoteService   = new QuoteServices();

            orderVMLight                             = new OrderViewModelLight();
            orderVMLight.BusinessId                  = 206680765352640513;
            orderVMLight.ShipToAddressId             = 479102086194151432;
            orderVMLight.PricingTypeId               = 1;
            orderVMLight.PONumber                    = "AAPO0613201601";
            orderVMLight.TotalDiscountPercent        = 0;
            orderVMLight.EstimatedReleaseDate        = Convert.ToDateTime("2016-06-06 00:00:00.000");
            orderVMLight.DeliveryAppointmentRequired = false;
            orderVMLight.DeliveryContactName         = "";
            orderVMLight.DeliveryContactPhone        = "";
            orderVMLight.OrderReleaseDate            = DateTime.Now.AddDays(2);
            orderVMLight.SubmittedByUserId           = 392643416367824896;
            orderVMLight.SubmitDate                  = DateTime.Now;
            orderVMLight.CreatedByUserId             = 392643416367824896;
            orderVMLight.UpdatedByUserId             = 392643416367824896;
            orderVMLight.DiscountRequestId           = 0;
            orderVMLight.CommissionRequestId         = 0;
            orderVMLight.ERPOrderNumber              = "";
            orderVMLight.ERPPOKey                    = 0;
            orderVMLight.ERPStatus                   = "Submitted";
            orderVMLight.Comments                    = "PLEASE CALL BEFORE SHIPPING";
            orderVMLight.ERPComments                 = "";
            orderVMLight.ERPOrderDate                = null;
            orderVMLight.ERPInvoiceDate              = null;
            orderVMLight.ERPShipDate                 = null;
            orderVMLight.ERPInvoiceNumber            = null;
            orderVMLight.QuoteId                     = 479102111284477952;
            orderVMLight.ProjectId                   = 479102086194151424;
            orderVMLight.CurrentUser                 = user;
            var fileUpload = new FileUploadTest();

            orderVMLight.POAttachment         = fileUpload;
            orderVMLight.POAttachmentFileName = fileUpload.FileUploadName;
            orderVMLight.ERPAccountId         = "1234";

            orderController = new OrderController();

            projects = this.db.Projects.Where(p => p.OwnerId == user.UserId).ToList();

            foreach (var project in projects)
            {
                var result = this.db.Context.Quotes.Where(q => q.AwaitingOrder == null && q.ProjectId == project.ProjectId).OrderByDescending(q => q.QuoteId).Select(q => new { q.QuoteId, q.ProjectId }).FirstOrDefault();
                if (result != null)
                {
                    quoteModel = quoteService.GetQuoteModel(user, result.ProjectId, result.QuoteId).Model as QuoteModel;
                    if (quoteModel != null)
                    {
                        quotesModelWithoutOrder.Add(quoteModel);
                    }
                }
            }

            foreach (var project in projects)
            {
                var result = this.db.Context.Quotes.Where(q => q.AwaitingOrder == true && q.ProjectId == project.ProjectId).OrderByDescending(q => q.QuoteId).Select(q => new { q.QuoteId, q.ProjectId }).FirstOrDefault();
                if (result != null)
                {
                    quoteModel = quoteService.GetQuoteModel(user, result.ProjectId, result.QuoteId).Model as QuoteModel;
                    if (quoteModel != null)
                    {
                        quotesModelWithOrder.Add(quoteModel);
                    }
                }
            }
        }
예제 #24
0
        public void CreateOrderFormPdfForSendMail(OrderViewModelLight orderVMLight)
        {
            log.InfoFormat("Enter CreateOrderFormPdfForSendMail");

            long quoteId    = orderVMLight.QuoteId;
            long projectId  = orderVMLight.ProjectId;
            var  urlAuth    = Utilities.DocumentServerURL();
            var  controller = string.Format("{0}/{1}", urlAuth, "ProjectDashboard");

            var urlOrderFormBody   = string.Format("{0}/{1}?orderId={2}&projectId={3}&quoteId={4}", controller, "OrderPrint", orderVMLight.OrderId, projectId, quoteId);
            var urlOrderFormHeader = string.Format("{0}/{1}", controller, "OrderPrintHeader", projectId, quoteId);
            var urlOrderFormFooter = string.Format("{0}/{1}", controller, "OrderPrintFooter");

            log.DebugFormat("quoteId: {0}, projectId: {1}, url:{2}, controller:{3}",
                            quoteId, projectId, urlAuth, controller);

            log.DebugFormat("urlOrderFormBody: {0}", urlOrderFormBody);

            var pdf = new PdfConvertor();
            var web = new WebClientLocal(System.Web.HttpContext.Current);

            pdf.Options.NoLink             = false;
            pdf.Options.HeaderHtmlFormat   = web.DownloadString(urlOrderFormHeader);
            pdf.Options.FooterHtmlFormat   = web.DownloadString(urlOrderFormFooter);
            pdf.Options.FooterHtmlPosition = pdf.Options.OutputArea.Bottom - 1.25f;

            pdf.Options.OutputArea = new System.Drawing.RectangleF(0f, 1.25f, pdf.Options.OutputArea.Width, pdf.Options.OutputArea.Height - 2.5f);
            pdf.AppendHtml(web.DownloadString(urlOrderFormBody));

            string root        = System.Web.HttpContext.Current.Server.MapPath("~");
            string parent      = System.IO.Path.GetDirectoryName(root);
            string grandParent = System.IO.Path.GetDirectoryName(parent);

            log.DebugFormat("root directory: {0}", root);

            string _last5DigitsOfProjectId = orderVMLight.ProjectIdStr.Substring(orderVMLight.ProjectIdStr.Length - 5);
            string nameFile = "Daikin City Order " +
                              DateTime.Now.ToString("MM-dd-yyyy") +
                              "-" +
                              _last5DigitsOfProjectId + ".pdf";

            string subPath = grandParent + "/CustomerDataFiles/OrderSubmitFiles/" + orderVMLight.QuoteId;

            log.DebugFormat("subPath: {0}", subPath);

            bool exists = System.IO.Directory.Exists(subPath);

            if (!exists)
            {
                System.IO.Directory.CreateDirectory(subPath);
            }

            string filePath = grandParent + "/CustomerDataFiles/OrderSubmitFiles/" + orderVMLight.QuoteId + "/" + nameFile;

            log.DebugFormat("filePath: {0}", filePath);

            try
            {
                pdf.Document.Save(filePath);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Create pdf error for file name:{0}", filePath);
                log.ErrorFormat("Error Message: {0}", ex.Message);
                log.ErrorFormat("Error Details Message: {0}", ex.InnerException.Message);
                log.ErrorFormat("Error Stack Trace: {0}", ex.StackTrace);
            }

            log.InfoFormat("Finished CreateOrderFormPdfForSendMail");
        }
예제 #25
0
        public ActionResult SendEmailOrderSubmit(OrderViewModelLight orderVMLight)
        {
            log.InfoFormat("Involke SendEmailOrderSubmit ControllerAction");

            CreateOrderFormPdfForSendMail(orderVMLight);

            var emailModel = this.orderService.getOrderSendEmailModel(orderVMLight);

            emailModel.HelpLink = "mailto:[email protected]";

            var fromEmails = Utilities.Config("dpo.sys.email.ordersubmit").Split(',').ToList();

            if (orderVMLight.HasConfiguredModel)
            {
                emailModel.Subject = string.Format("BTO - An Order has been submitted by " + orderVMLight.BusinessName + " - Project: " + orderVMLight.ProjectName);
            }
            else
            {
                emailModel.Subject = string.Format("An Order has been submitted by " + orderVMLight.BusinessName + " - Project: " + orderVMLight.ProjectName);
            }


            emailModel.From = new MailAddress(fromEmails.First(), "DPO Order");

            foreach (string email in fromEmails)
            {
                emailModel.To.Add(new MailAddress(email, "Daikin Project Desk"));
            }

            //Todo: propery need to check for EmailAccount or EmailAccountManager is null
            //if model return null. maybe need to write code to reget it from db
            //currently it based on value of ViewModel.

            AccountServices  accountService  = new AccountServices();
            UserSessionModel admin           = accountService.GetUserSessionModel(orderVMLight.CreatedByUserId).Model as UserSessionModel;
            BusinessServices businessService = new BusinessServices();
            BusinessModel    businessModel   = businessService.GetBusinessModel(admin, admin.BusinessId).Model as BusinessModel;

            if (!string.IsNullOrEmpty(emailModel.AccountManagerEmail))
            {
                emailModel.To.Add(new MailAddress(emailModel.AccountManagerEmail));
            }
            else
            {
                var emailAccountManager = businessModel.AccountManagerEmail;
                if (emailAccountManager != null)
                {
                    emailModel.AccountManagerEmail = emailAccountManager;
                }
            }

            log.DebugFormat("Account Manager Email: {0}", emailModel.AccountManagerEmail);

            if (emailModel.AccountOwnerEmail != null)
            {
                emailModel.To.Add(new MailAddress(emailModel.AccountOwnerEmail));
            }
            else
            {
                var emailAccountOwner = businessModel.AccountOwnerEmail;
                if (emailAccountOwner != null)
                {
                    emailModel.AccountOwnerEmail = emailAccountOwner;
                }
            }

            if (CurrentUser.Email != null)
            {
                emailModel.To.Add(new MailAddress(CurrentUser.Email));
            }

            if (!string.IsNullOrEmpty(orderVMLight.ProjectOwnerId.ToString()))
            {
                UserServices userService  = new UserServices();
                var          projectOwner = userService.GetUserModel(CurrentUser, orderVMLight.ProjectOwnerId, true, true).Model as UserModel;
                if (projectOwner != null && !string.IsNullOrEmpty(projectOwner.Email))
                {
                    if (CurrentUser.Email != null && CurrentUser.Email != projectOwner.Email)
                    {
                        emailModel.To.Add(new MailAddress(projectOwner.Email));
                    }
                }
            }

            log.DebugFormat("AccountOwnerEmail: {0}", emailModel.AccountOwnerEmail);

            string root                    = Server.MapPath("~");
            string parent                  = System.IO.Path.GetDirectoryName(root);
            string grandParent             = System.IO.Path.GetDirectoryName(parent);
            string _last5DigitsOfProjectId = orderVMLight.ProjectIdStr.Substring(orderVMLight.ProjectIdStr.Length - 5);

            string OrderPdfFile = "Daikin City Order " +
                                  DateTime.Now.ToString("MM-dd-yyyy") +
                                  "-" +
                                  _last5DigitsOfProjectId + ".pdf";

            string OrderPdfFilePath = grandParent + "/CustomerDataFiles/OrderSubmitFiles/" + orderVMLight.QuoteId + "/" + OrderPdfFile;

            log.DebugFormat("OrderPdfFilePath: {0}", OrderPdfFilePath);

            string DARPdfFile = "Daikin City Discount Request " +
                                DateTime.Now.ToString("MM-dd-yyyy") +
                                "-" +
                                _last5DigitsOfProjectId + ".pdf";

            string DARPdfFilePath = grandParent + Utilities.Config("dpo.setup.customerdata.location") + "DiscountRequestFiles/" + orderVMLight.QuoteId + "/" + DARPdfFile;

            log.DebugFormat("DarPdfFilePath: {0}", DARPdfFilePath);

            string COMPdfFile     = orderVMLight.CommissionRequestId.ToString() + ".pdf";
            string COMPdfFilePath = grandParent + "/CustomerDataFiles/DiscountRequestFiles/" + orderVMLight.QuoteId + "/" + COMPdfFile;

            log.DebugFormat("COMPdfFilePath: {0}", COMPdfFilePath);

            if (orderVMLight.DiscountRequestId != null)
            {
                if (System.IO.File.Exists(DARPdfFilePath))
                {
                    orderVMLight.DARAttachmentFileName = DARPdfFilePath;
                }
                else
                {
                    orderVMLight.DARAttachmentFileName = System.IO.Directory.GetFiles(grandParent + Utilities.Config("dpo.setup.customerdata.location") + "DiscountRequestFiles/").FirstOrDefault();
                }
            }
            else
            {
                var discountRequest = discountRequestService.GetDiscountRequestModel(this.CurrentUser, orderVMLight.ProjectId, orderVMLight.QuoteId).Model as DiscountRequestModel;

                if (discountRequest.DiscountRequestId != null)
                {
                    orderVMLight.DiscountRequestId = discountRequest.DiscountRequestId;
                }

                if (orderVMLight.DiscountRequestId != null && orderVMLight.DiscountRequestId > 0)
                {
                    if (System.IO.File.Exists(DARPdfFilePath))
                    {
                        orderVMLight.DARAttachmentFileName = DARPdfFilePath;
                    }
                    else
                    {
                        string currentDARDirectory = grandParent + Utilities.Config("dpo.setup.customerdata.location") + @"DiscountRequestFiles\" + orderVMLight.QuoteId + @"\";
                        if (System.IO.Directory.Exists(currentDARDirectory))
                        {
                            orderVMLight.DARAttachmentFileName = System.IO.Directory.GetFiles(currentDARDirectory, "*.pdf").FirstOrDefault();
                        }
                        else
                        {
                            CreateDarPdfForSendMail(discountRequest);
                            orderVMLight.DARAttachmentFileName = System.IO.Directory.GetFiles(currentDARDirectory, "*.pdf").FirstOrDefault();
                        }
                    }

                    emailModel.order.RequestedDiscountPercentage = (discountRequest != null & discountRequest.RequestedDiscount > 0) ? discountRequest.RequestedDiscount : 0;
                    emailModel.order.ApprovedDiscountPercentage  = (discountRequest != null && discountRequest.ApprovedDiscount > 0) ? discountRequest.ApprovedDiscount : 0;
                }
            }

            log.DebugFormat("RequesteDiscountPercentage: {0}", emailModel.order.RequestedDiscountPercentage);
            log.DebugFormat("ApprovedDiscountPercentage: {0}", emailModel.order.ApprovedDiscountPercentage);

            if (emailModel.order.ProjectDate == DateTime.MinValue)
            {
                emailModel.order.ProjectDate = orderVMLight.ProjectDate;
                if (emailModel.order.ProjectDate == DateTime.MinValue)
                {
                    var project = projectService.GetProjectModel(this.CurrentUser, orderVMLight.ProjectId).Model as ProjectModel;
                    emailModel.order.ProjectDate = project.ProjectDate.Value;
                }
            }

            log.DebugFormat("Project Date: {0}", emailModel.order.ProjectDate);

            if (orderVMLight.CommissionRequestId != null)
            {
                orderVMLight.COMAttachmentFileName = COMPdfFilePath;
            }

            if (orderVMLight.OrderId != 0 || orderVMLight.QuoteId != 0)
            {
                orderVMLight.OrderAttachmentFileName = OrderPdfFilePath;
            }

            emailModel.OrderAttachmentFile = orderVMLight.OrderAttachmentFileName;
            emailModel.DARAttachmentFile   = orderVMLight.DARAttachmentFileName;
            emailModel.COMAttachmentFile   = orderVMLight.COMAttachmentFileName;

            if (orderVMLight.DiscountRequestId != null && orderVMLight.DiscountRequestId > 0)
            {
                log.DebugFormat("DARAttachmentFile: {0}", emailModel.DARAttachmentFile);
            }
            if (orderVMLight.CommissionRequestId != null && orderVMLight.CommissionRequestId > 0)
            {
                log.DebugFormat("COMAttachmentFile: {0}", emailModel.COMAttachmentFile);
            }

            log.DebugFormat("OrderAttachmentFile: {0}", emailModel.OrderAttachmentFile);

            //string[] filePaths = Directory.GetFiles(grandParent + "/CustomerDataFiles/POAttachment/" + orderVMLight.QuoteId + "/", "*.*",
            //                         SearchOption.AllDirectories);

            if (emailModel.OtherAttachmentFiles == null)
            {
                emailModel.OtherAttachmentFiles = new List <string>();
            }

            var uploadDirectory  = new System.IO.DirectoryInfo(Utilities.GetPOAttachmentDirectory(orderVMLight.QuoteId));
            var LatestUploadFile = (from f in uploadDirectory.GetFiles()
                                    orderby f.LastWriteTime descending
                                    select f).First();

            if (LatestUploadFile != null)
            {
                emailModel.OtherAttachmentFiles.Add(LatestUploadFile.FullName);
            }

            SendEmailModel sendEmailModel = emailModel;

            sendEmailModel.DARAttachmentFile     = (emailModel.DARAttachmentFile != null) ? emailModel.DARAttachmentFile : null;
            sendEmailModel.COMAttachmentFile     = (emailModel.COMAttachmentFile != null) ? emailModel.COMAttachmentFile : null;
            sendEmailModel.DARAttachmentFileName = DARPdfFile;
            sendEmailModel.COMAttachmentFileName = COMPdfFile;

            if (orderVMLight.DiscountRequestId != null && orderVMLight.DiscountRequestId > 0)
            {
                log.DebugFormat("sendEmailModel.DARAttachmentFile: {0}", sendEmailModel.DARAttachmentFile);
                log.DebugFormat("sendEmailModel.DARAttachmentFileName: {0}", sendEmailModel.DARAttachmentFileName);
            }
            if (orderVMLight.CommissionRequestId != null && orderVMLight.CommissionRequestId > 0)
            {
                log.DebugFormat("sendEmailModel.COMAttachmentFile: {0}", sendEmailModel.COMAttachmentFile);
                log.DebugFormat("sendEmailModel.COMAttachmentFileName: {0}", sendEmailModel.COMAttachmentFileName);
            }

            sendEmailModel.OrderAttachmentFile     = (emailModel.OrderAttachmentFile != null) ? emailModel.OrderAttachmentFile : null;
            sendEmailModel.OrderAttachmentFileName = OrderPdfFile;

            log.DebugFormat("sendEmailModel.OrderAttachmentFile: {0}", sendEmailModel.OrderAttachmentFile);
            log.DebugFormat("sendEmailModel.OrderAttachmentFileName: {0}", sendEmailModel.OrderAttachmentFileName);

            sendEmailModel.OtherAttachmentFiles = emailModel.OtherAttachmentFiles;

            if (sendEmailModel.OtherAttachmentFiles.Count > 0)
            {
                log.DebugFormat("sendEmailModel.OtherAttachmentFiles: {0}", sendEmailModel.OtherAttachmentFiles);
            }

            emailModel.RenderTextVersion = true;
            emailModel.BodyTextVersion   = RenderView(this, "SendEmailOrderSubmit", emailModel);

            emailModel.RenderTextVersion = false;
            emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailOrderSubmit", emailModel);

            sendEmailModel.ProjectId = orderVMLight.ProjectId;
            sendEmailModel.QuoteId   = orderVMLight.QuoteId;

            try
            {
                log.DebugFormat("Start sending Order submit email....");
                new EmailServices().SendEmail(sendEmailModel);
            }
            catch (Exception ex)
            {
                log.DebugFormat("Start sending Order Submit error email.... ");
                SendEmailToTeamWhenFailToSendEmailOnOrder(orderVMLight.QuoteId, ex.Message);
            }

            return(null);
        }
예제 #26
0
        public void RulesOnValidateModel(OrderViewModelLight model)
        {
            this.Response.Messages.Clear();

            //if (!model.IsValidEmails)
            //{
            //    this.Response.Messages.AddError(Resources.ResourceModelProject.MP117);

            //    string errorMessage = "The following emails are not associated with DaikinCity account: ";
            //    for (int i = 0; i < model.InvalidEmails.Count; i++)
            //    {
            //        if (i == model.InvalidEmails.Count)
            //        {
            //            errorMessage += model.InvalidEmails[i];
            //        }
            //        else
            //        {
            //            errorMessage += model.InvalidEmails[i] + ",";
            //        }
            //    }

            //    this.Response.Messages.AddError(errorMessage);
            //}


            //if (model.Project.BidDate == null)
            //{
            //    this.Response.Messages.AddError("ProjectBidDate", Resources.ResourceModelProject.MP120);
            //}
            //else if (model.Project.BidDate < model.Project.EstimatedClose)
            //{
            //    this.Response.Messages.AddError("ProjectBidDateInvalid", Resources.ResourceModelProject.MP003);
            //}
            //if (model.Project.EstimatedClose == null)
            //{
            //    this.Response.Messages.AddError("EstimateCloseDate", Resources.ResourceModelProject.MP121);
            //}
            //else if (model.Project.EstimatedClose > model.Project.EstimatedDelivery)
            //{
            //    this.Response.Messages.AddError("EstimateCloseDate", Resources.ResourceModelProject.MP002);
            //}

            //if (model.Project.EstimateReleaseDate == null)
            //{
            //    this.Response.Messages.AddError("Estimate Delivery Date not set");
            //}
            //else if (model.Project.EstimateReleaseDate > model.Project.EstimatedDelivery.Value.AddDays(10))
            //{
            //    this.Response.Messages.AddError("EstimateDeliveryDateInvalid", Resources.ResourceModelProject.MP128);
            //}

            //if (model.Project.ActualCloseDate == null)
            //{
            //    if (model.SubmitDate != null)
            //    {
            //        model.Project.ActualCloseDate = model.SubmitDate.Value;
            //    }
            //    else
            //    {
            //        model.Project.ActualCloseDate = DateTime.Now;
            //    }
            //}

            if (model.ERPAccountId == null)
            {
                this.Response.Messages.AddError(Resources.ResourceModelBusiness.BM010);
            }

            if (model.CurrentUser == null)
            {
                this.Response.Messages.AddError(Resources.ResourceModelUser.MU024);
            }
            else if (model.CurrentUser.Email == null)
            {
                this.Response.Messages.AddError(Resources.ResourceModelProject.MP124);
            }

            if (model.CurrentUser != null && !model.CurrentUser.ShowPrices)
            {
                this.Response.Messages.AddError(Resources.ResourceModelBusiness.BM008);
            }

            if (model.POAttachmentFileName == null || model.POAttachmentFileName == string.Empty)
            {
                this.Response.Messages.AddError("POAttachment", ResourceUI.POAttachmentRequired);
            }

            if (model.OrderReleaseDate == null || model.OrderReleaseDate == DateTime.MinValue)
            {
                this.Response.Messages.AddError("OrderReleaseDate", Resources.ResourceModelProject.MP133);
            }

            if (model.OrderReleaseDate < model.SubmitDate)
            {
                this.Response.Messages.AddError(Resources.ResourceModelProject.MP134);
            }

            if (model.DeliveryAppointmentRequired)
            {
                if (model.DeliveryContactName == null || model.DeliveryContactName.Length == 0)
                {
                    this.Response.Messages.AddError("DeliveryContactName", ResourceModelProject.MP139);
                }
                if (model.DeliveryContactPhone == null || model.DeliveryContactPhone.Length == 0)
                {
                    this.Response.Messages.AddError("DeliveryContactPhone", ResourceModelProject.MP138);
                }
            }

            //validate the POfile name for invalid character
            if ((model.POAttachment != null && model.POAttachment.FileName != null) || model.POAttachmentFileName != null)
            {
                List <String> replaceCharacters = new List <String> {
                    "@", "%", "*", "#", "&"
                };
                List <string> removeCharacters = new List <string> {
                    "'", "~"
                };
                foreach (string chac in replaceCharacters)
                {
                    model.POAttachmentFileName = model.POAttachmentFileName.Replace(chac, "_");

                    if (model.OrderAttachmentFileName != null)
                    {
                        model.OrderAttachmentFileName.Replace(chac, "_");
                    }
                }
                foreach (string chac in removeCharacters)
                {
                    if (model.OrderAttachmentFileName != null)
                    {
                        model.OrderAttachmentFileName.Replace(chac, "");
                    }
                }
            }
        }
예제 #27
0
        private void SendApprovalRejectionEmail(OrderViewModelLight orderVMLight)
        {
            UserServices userSerivce = new UserServices();

            var user = new UserSessionModel();

            #pragma warning disable CS0472 // The result of the expression is always 'true' since a value of type 'long' is never equal to 'null' of type 'long?'
            if (orderVMLight.ProjectOwnerId != null)
            #pragma warning restore CS0472 // The result of the expression is always 'true' since a value of type 'long' is never equal to 'null' of type 'long?'
            {
                user = new AccountServices().GetUserSessionModel(orderVMLight.ProjectOwnerId).Model as UserSessionModel;
            }

            var orderEmailModel = new SendEmailApprovalModel();
            orderEmailModel.HelpLink = "mailto:[email protected]";

            orderEmailModel.Subject = string.Format("The status of an Order request has changed");

            orderEmailModel.Reason           = orderVMLight.Comments;
            orderEmailModel.ProjectId        = orderVMLight.ProjectId;
            orderEmailModel.ProjectName      = orderVMLight.ProjectName;
            orderEmailModel.QuoteTitle       = orderVMLight.QuoteTitle;
            orderEmailModel.ERPOrderNumber   = (orderVMLight.ERPOrderNumber != null) ? orderVMLight.ERPOrderNumber : string.Empty;
            orderEmailModel.ERPInvoiceNumber = (orderVMLight.ERPInvoiceNumber != null) ? orderVMLight.ERPInvoiceNumber : string.Empty;
            orderEmailModel.ERPPOKey         = (orderVMLight.ERPPOKey != null) ? orderVMLight.ERPPOKey.Value : 0;
            orderEmailModel.ERPInvoiceDate   = (orderVMLight.ERPInvoiceDate != null) ? orderVMLight.ERPInvoiceDate.Value : DateTime.Now;
            orderEmailModel.ERPOrderDate     = (orderVMLight.ERPOrderDate != null) ? orderVMLight.ERPOrderDate.Value : DateTime.Now;
            #pragma warning disable CS0472 // The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
            orderEmailModel.TotalNet = (orderVMLight.TotalNetPrice != null) ? orderVMLight.TotalNetPrice : 0;
            #pragma warning restore CS0472 // The result of the expression is always 'true' since a value of type 'decimal' is never equal to 'null' of type 'decimal?'
            orderEmailModel.Approved     = (orderVMLight.OrderStatusTypeId == OrderStatusTypeEnum.InProcess);
            orderEmailModel.ModifierName = (user != null) ? user.FirstName + " " + user.LastName : orderVMLight.UpdatedByUserIdStr;

            orderEmailModel.ProjectOwnerName = (orderVMLight.ProjectOwner != null) ? orderVMLight.ProjectOwner : user.FirstName + " " + user.LastName;
            orderEmailModel.ProjectDate      = (orderVMLight.ProjectDate != null) ? orderVMLight.ProjectDate : DateTime.Now;

            var business = new BusinessServices().GetBusinessModel(user, user.BusinessId, false).Model as BusinessModel;
            orderEmailModel.BusinessName = (business != null && business.BusinessName != null) ? business.BusinessName : "No Business Name";

            orderEmailModel.From = new MailAddress(Utilities.Config("dpo.sys.email.discountrequest"), "DPO Project Desk");

            orderEmailModel.To.Add(orderEmailModel.From);

            if (!string.IsNullOrEmpty(business.AccountManagerEmail))
            {
                orderEmailModel.To.Add(new MailAddress(business.AccountManagerEmail));
            }

            if (!string.IsNullOrEmpty(business.AccountOwnerEmail))
            {
                orderEmailModel.To.Add(new MailAddress(business.AccountOwnerEmail));
            }

            orderEmailModel.RenderTextVersion = true;
            orderEmailModel.BodyTextVersion   = RenderView(this, "SendEmailOrderApproval", orderEmailModel);

            orderEmailModel.RenderTextVersion = false;
            orderEmailModel.BodyHtmlVersion   = RenderView(this, "SendEmailOrderApproval", orderEmailModel);

            new EmailServices().SendEmail(orderEmailModel);
        }
        public ServiceResponse GetOrderModel(UserSessionModel user, OrderViewModelLight qto)
        {
            OrderViewModelLight model = null;

            if (!string.IsNullOrEmpty(qto.QuoteId.ToString()))
            {
                var query = from order in this.Db.QueryOrdersViewableByUser(user)

                            join mod in this.Db.Users on order.UpdatedByUserId equals mod.UserId into Lmod
                            from mod in Lmod.DefaultIfEmpty()
                            join project in this.Db.Projects on order.Quote.ProjectId equals project.ProjectId
                            join quote in this.Db.Quotes on order.QuoteId equals quote.QuoteId
                            join owner in this.Db.Users on project.OwnerId equals owner.UserId
                            join business in this.Db.Businesses on owner.BusinessId equals business.BusinessId
                            join ort in this.Context.OrderAttachments on order.OrderId equals ort.OrderId
                            where order.OrderId == qto.OrderId
                            select new OrderViewModelLight
                {
                    OrderId              = order.OrderId,
                    ProjectId            = order.Quote.ProjectId,
                    QuoteId              = order.QuoteId,
                    ProjectOwner         = owner.FirstName + " " + owner.LastName,
                    ProjectOwnerId       = owner.UserId,
                    BusinessId           = owner.BusinessId.Value,
                    BusinessName         = business.BusinessName,
                    OrderStatusTypeId    = (OrderStatusTypeEnum)order.OrderStatusTypeId,
                    CreatedByUserId      = mod.UserId,
                    UpdatedByUserId      = mod.UserId,
                    UpdatedByUser        = mod.FirstName + " " + mod.LastName,
                    DiscountRequestId    = order.DiscountRequestId,
                    CommissionRequestId  = order.CommissionRequestId,
                    ShipToAddressId      = order.ShipToAddressId,
                    PricingTypeId        = order.PricingTypeId,
                    PONumber             = order.PONumber,
                    TotalDiscountPercent = order.TotalDiscountPercent,
                    Comments             = order.Comments,
                    //EstimatedReleaseDate = order.EstimatedReleaseDate,
                    EstimatedDeliveryDate       = (project.EstimatedDelivery != null) ? project.EstimatedDelivery : DateTime.Now,
                    DeliveryAppointmentRequired = order.DeliveryAppointmentRequired,
                    DeliveryContactName         = order.DeliveryContactName,
                    DeliveryContactPhone        = order.DeliveryContactPhone,
                    SubmittedByUserId           = mod.UserId,
                    //SubmitDate = (order.SubmitDate != null) ? order.SubmitDate : DateTime.Now,
                    SubmitDate = (DateTime)order.SubmitDate,

                    ProjectDate          = (project.ProjectDate != null) ? project.ProjectDate : DateTime.Now,
                    ERPOrderDate         = (order.ERPOrderDate != null) ? order.ERPOrderDate.Value : (System.DateTime?)null,
                    ERPInvoiceNumber     = (order.ERPInvoiceNumber != null) ? order.ERPInvoiceNumber : null,
                    ERPComments          = (order.ERPComment != null) ? order.ERPComment : null,
                    ERPPOKey             = (order.ERPPOKey != null) ? order.ERPPOKey.Value : (int?)null,
                    ERPStatus            = (order.ERPStatus != null) ? order.ERPStatus : null,
                    POAttachmentFileName = ort.FileName,
                    Timestamp            = (order.Timestamp != null) ? order.Timestamp : DateTime.Now
                };

                model = query.FirstOrDefault();
            }

            if (model == null)
            {
                model = new OrderViewModelLight
                {
                    OrderStatusTypeId = OrderStatusTypeEnum.NewRecord,
                    QuoteId           = qto.QuoteId
                };
            }

            finaliseModelSvc.FinaliseOrderModel(this.Response.Messages, user, model);
            this.Response.Model = model;

            return(this.Response);
        }
예제 #29
0
        public ServiceResponse CheckWithMapicsBeforeSavingToDb(List <OrderItemsViewModel> orderItemsVm, Order order,
                                                               OrderViewModelLight model)
        {
            var orderDetailList = new List <OrderDetail>(); // array of order detail to send it to mapics
            var address         = Db.Addresses.FirstOrDefault(x => x.AddressId == model.ShipToAddressId);
            var state           = Db.States.FirstOrDefault(x => x.StateId == address.StateId);

            var increment = 1;

            foreach (var item in orderItemsVm)
            {
                var orderDetail = new OrderDetail()
                {
                    LineSeq            = increment,
                    ProductNumber      = item.ProductNumber,
                    CustomerProductNo  = "",
                    Quantity           = item.Quantity,
                    NetPrice           = item.NetPrice,
                    ExtendedNetPrice   = item.ExtendedPrice,
                    ProductDescription = "",
                    DiscountPercent    = item.DiscountPercentage,
                    CompanyNo          = 1,
                };
                increment++;

                orderDetailList.Add(orderDetail);
            }

            //construct json array to post it to mapics
            var jsonData = new ERPOrderInfo
            {
                CustomerNumber    = !string.IsNullOrWhiteSpace(model.ERPAccountId) ? Convert.ToInt32(model.ERPAccountId) : 0,
                PONo              = model.PONumber,
                PODate            = DateTime.Today,
                RequestDate       = model.OrderReleaseDate,
                TermsCode         = "",
                OrderType         = "DK",
                ShipToName        = model.ShipToName,
                ShipToAddress1    = address?.AddressLine1,
                ShipToAddress2    = address?.AddressLine2,
                ShipToCity        = address?.Location,
                ShipToState       = state?.Code,
                ShipToZip         = address?.PostalCode,
                ShipToInstruction = order.Comments,  ///From Delivery notes
                ContactName       = model.DeliveryContactName,
                ContactPhone      = model.DeliveryContactPhone,
                TotalAmount       = model.TotalNetPrice,
                OrderCode         = "DK",
                Status            = model.ERPStatus,
                ShipToNumber      = null,
                CompanyNo         = 1,
                BusinessID        = model.BusinessId.GetValueOrDefault(),
                BusinessName      = model.BusinessName,
                ProjectID         = model.ProjectId,
                ProjectName       = model.ProjectName,
                ProjectRefID      = null,
                QuoteID           = model.QuoteId,
                QuoteRefID        = null,
                Comments          = model.Comments,
                DiscountPercent   = 0,
                Details           = orderDetailList?.ToArray()
            };

            using (var erpClient = new ERPClient())
            {
                this.Response = erpClient.PostOrderToMapicsAsync(jsonData);
            }

            return(this.Response);
        }
예제 #30
0
        public void TestOrderViews_ShouldRenderOrderDetails()
        {
            OrderViewModelLight orderVMLight = _orderServiceLight.GetNewOrder(user, _quoteId).Model as OrderViewModelLight;

            _driver.Navigate().GoToUrl(@"http://tstsysdcity2/projectdashboard/OrderForm/" + _projectId + "/" + _quoteId + "#!/");

            Thread.Sleep(25000);//This is make sure we completed load the form before we manipulate DOM

            ReadOnlyCollection <IWebElement> orderDetailsLists = _driver
                                                                 .FindElement(By.Id("orderDetailsDiv"))
                                                                 .FindElements(By.ClassName("details-list"));

            ReadOnlyCollection <IWebElement> orderDetailsList1 = orderDetailsLists[0]
                                                                 .FindElement(By.TagName("ul"))
                                                                 .FindElements(By.TagName("li"));

            List <string> values = new List <string>();

            foreach (var item in orderDetailsList1)
            {
                ReadOnlyCollection <IWebElement> children = item.FindElements(By.XPath(".//*"));
                if (children.Count() < 3)
                {
                    if (children[1].Text != string.Empty)
                    {
                        values.Add(children[1].Text);
                    }
                }
            }

            ReadOnlyCollection <IWebElement> orderDetailsList2 = orderDetailsLists[1]
                                                                 .FindElement(By.TagName("ul"))
                                                                 .FindElements(By.TagName("li"));

            foreach (var item in orderDetailsList2)
            {
                ReadOnlyCollection <IWebElement> children = item.FindElements(By.XPath(".//*"));
                if (children.Count() < 3)
                {
                    if (children[1].Text != string.Empty)
                    {
                        values.Add(children[1].Text);
                    }
                }
            }

            if (values.Count() > 1)
            {
                for (int a = 0; a < values.Count; a++)
                {
                    if (a != values.Count() - 1)
                    {
                        Assert.That(values[a], Is.Not.EqualTo(null));
                    }
                }

                for (int i = 0; i < values.Count(); i++)
                {
                    switch (i)
                    {
                    case 0:
                        Assert.That(values[i], Is.EqualTo(orderVMLight.SubmittedByUserName));
                        break;

                    case 1:
                        if (orderVMLight.OrderId != 0)
                        {
                            Assert.That(values[i], Is.EqualTo(orderVMLight.OrderReleaseDate.ToString("MM/dd/yyyy")));
                        }
                        break;

                    case 2:
                        if (orderVMLight.OrderId != 0)
                        {
                            Assert.That(values[i], Is.EqualTo(orderVMLight.PONumber));
                        }
                        break;

                    case 3:
                        Assert.That(values[i], Is.EqualTo(orderVMLight.TotalNetPrice.ToString()));
                        break;

                    case 4:
                        Assert.That(values[i], Is.EqualTo(orderVMLight.TotalDiscountPercent.ToString()));
                        break;

                    case 5:
                        if (orderVMLight.OrderId != 0)
                        {
                            Assert.That(values[i], Is.EqualTo(orderVMLight.Comments));
                        }
                        break;
                    }
                }
            }
        }