public bool UpdateAPIDelivery(Delivery modelData, FCMNotificationModel FCMModelData)
        {
            bool bSuccess = false;

            try
            {
                if (modelData.DeliveryId > 0)
                {
                    ProDelivery deliveryData = deliveryRepository.GetDelivery(modelData.DeliveryId);
                    deliveryData.ModifiedOn      = DateTime.Now;
                    deliveryData.ModifiedBy      = modelData.DriverId;
                    deliveryData.DeliveryStatus  = modelData.DeliveryStatus;
                    deliveryData.DeliveredTo     = modelData.DeliveredTo;
                    deliveryData.DeliveryRemarks = modelData.DeliveryRemarks;
                    bSuccess = deliveryRepository.SaveDelivery(deliveryData);
                    if (bSuccess)
                    {
                        ProOrder orderData = orderRepository.GetOrder(deliveryData.OrderId.Value);
                        orderData.ModifiedOn = DateTime.Now;
                        orderData.ModifiedBy = modelData.DriverId;
                        Model.Order orderModelData = new Model.Order();
                        int?        orderOldStatus = orderData.OrderStatus;
                        orderData.OrderStatus  = (int)GetOrderStatusForDeliveryStatus((DeliveryStatus)deliveryData.DeliveryStatus);
                        orderModelData.Remarks = $"Changed status to {GetOrderStatusForDeliveryStatus((DeliveryStatus)deliveryData.DeliveryStatus).ToString()}";
                        bSuccess = orderRepository.SaveOrder(orderData, orderModelData);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
            }
            return(bSuccess);
        }
        public bool SaveDelivery(Delivery modelData, FCMNotificationModel FCMModelData)
        {
            bool bSuccess = false;

            try
            {
                ProDelivery deliveryData;
                if (modelData.DeliveryId > 0)
                {
                    deliveryData         = deliveryRepository.GetDelivery(modelData.DeliveryId);
                    modelData.ModifiedOn = DateTime.Now;
                    modelData.ModifiedBy = userService.GetLoggdInUser().UserId;
                }
                else
                {
                    deliveryData             = new ProDelivery();
                    modelData.CreatedOn      = DateTime.Now;
                    modelData.CreatedBy      = userService.GetLoggdInUser().UserId;
                    modelData.CompanyId      = userService.GetLoggdInUser().CompanyId;
                    modelData.BranchId       = userService.GetLoggdInUser().BranchId;;
                    modelData.DeliveryStatus = (int)DeliveryStatus.NotReady;
                }
                if (modelData.InputDeliveryDate.HasValue)
                {
                    modelData.DeliveryDate = modelData.InputDeliveryDate.Value;
                }
                deliveryData = MapperConfig.Mapper.Map <Delivery, ProDelivery>(modelData, deliveryData);
                bSuccess     = deliveryRepository.SaveDelivery(deliveryData);
                if (bSuccess)
                {
                    ProOrder orderData = orderRepository.GetOrder(modelData.OrderId);
                    orderData.ModifiedOn = DateTime.Now;
                    orderData.ModifiedBy = userService.GetLoggdInUser().UserId;
                    Model.Order orderModelData = new Model.Order();
                    int?        orderOldStatus = orderData.OrderStatus;
                    orderData.OrderStatus  = (int)GetOrderStatusForDeliveryStatus((DeliveryStatus)modelData.DeliveryStatus);
                    orderModelData.Remarks = $"Changed status to {GetOrderStatusForDeliveryStatus((DeliveryStatus)modelData.DeliveryStatus).ToString()}";
                    bSuccess = orderRepository.SaveOrder(orderData, orderModelData);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
            }
            return(bSuccess);
        }
Esempio n. 3
0
        private string GetChangedDetail(ProOrder modelData)
        {
            string changes    = "";
            var    properties = typeof(ProOrder).GetProperties();
            var    OrderTypes = dbContext.MasOrderType.ToList();
            var    PickTypes  = dbContext.MasPickupType.ToList();

            using (var command = dbContext.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = $"SELECT * FROM [ProOrder] WHERE OrderId={modelData.OrderId}";
                dbContext.Database.OpenConnection();
                string[] memoFields = { "OrderStatus", "DeliveryNote", "BranchNote", "PickupTypeId", "OrderTypeId", "DeliveryDate", "IsStorageFridge", "IsControlledDrugs", "RackNo" };
                using (var result = command.ExecuteReader())
                {
                    if (result.HasRows)
                    {
                        if (result.Read())
                        {
                            foreach (var item in properties)
                            {
                                if (memoFields.Contains(item.Name))
                                {
                                    var newValue = item.GetValue(modelData);
                                    var oldValue = result.GetFieldValue <object>(item.Name);
                                    if (!string.Equals(newValue, oldValue) && !(newValue == null && oldValue == DBNull.Value))
                                    {
                                        switch (item.Name)
                                        {
                                        case "OrderStatus":
                                            changes += $"<br /><b>Statuc</b> has been changed from {(OrderStatus)((int)oldValue)} to {(OrderStatus)((int)newValue)}";
                                            break;

                                        case "RackNo":
                                            changes += $"<br /><b>Location</b> has been changed from {oldValue} to {newValue}";
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(changes);
        }
Esempio n. 4
0
        public bool SaveAPIOrder(Model.Order modelData, string customerOrderMailContent, string surgeryOrderMailContent, FCMNotificationModel FCMModelData)
        {
            bool bSuccess = false;

            try
            {
                ProOrder orderData;
                orderData                     = new ProOrder();
                orderData.CreatedOn           = DateTime.Now;
                orderData.CreatedBy           = modelData.CreatedBy;
                orderData.CompanyId           = modelData.CompanyId;
                orderData.BranchId            = modelData.BranchId;
                orderData.OrderDate           = DateTime.Now;
                orderData.OrderTypeId         = modelData.OrderTypeId;
                orderData.PickupTypeId        = modelData.PickupTypeId;
                orderData.OrderStatus         = (int)OrderStatus.Requested;
                orderData.RequestPrescription = modelData.RequestPrescription;
                orderData.Customer            = customerRepository.GetCustomer(modelData.CustomerId);
                orderData.DocumentCaption     = modelData.DocumentCaption;
                orderData.DocumentPath        = modelData.DocumentPath;
                orderData.RecentDeliveryNote  = modelData.RecentDeliveryNote;
                orderData.DeliveryNote        = modelData.DeliveryNote;
                orderData.BranchNote          = modelData.BranchNote;
                orderData.SurgeryNote         = modelData.SurgeryNote;
                ProOrderDetail orderDetail;
                orderData.ProOrderDetail = new List <ProOrderDetail>();
                string emailItems = string.Empty;

                bSuccess = orderRepository.SaveOrder(orderData, modelData);
                if (bSuccess)
                {
                    if (orderData.CustomerId.HasValue)
                    {
                        var customerDtls = customerService.GetCustomer(orderData.CustomerId.Value);
                        var branchDtls   = branchRepositry.GetBranch(modelData.BranchId);
                        var branchInfo   = $@"<tr><td class='header-sm'>{branchDtls.BranchName}</td></tr><tr><td>{branchDtls.Address?.Address1}</td></tr><tr><td>{branchDtls.Address?.Address2}</td></tr>
				                            <tr><td>{branchDtls.Address.PostCode}</td></tr><tr><td>{branchDtls.Address.City}</td></tr>"                    ;



                        //Send notification
                        if (FCMModelData != null)
                        {
                            string orderUpdateSMSMessage = messageTemplateService.GetMessageTemplate(orderData.CompanyId.Value, (long)orderData.BranchId, (int)MessageTypes.SMS, (int)MessageEvents.OrderUpdate);

                            string branchName = orderData.BranchId.HasValue ? branchRepositry.GetBranch((long)orderData.BranchId).BranchName : string.Empty;
                            //FCMModelData.Notification = string.Format(ResourceService.Resource.GetMessage("NMOrderCreation"), orderData.OrderId);
                            FCMModelData.Notification = string.Format(orderUpdateSMSMessage, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), orderData.OrderId, customerDtls?.Mobile, branchName);
                            FCMService.SaveFCMNotificationUser(FCMModelData);

                            FCMModelData.CompanyId = orderData.CompanyId.Value;
                            FCMModelData.BranchId  = orderData.BranchId;
                            //FCMModelData.Notification = string.Format(ResourceService.Resource.GetMessage("NMOrderStatusChangeForDriver"), orderData.OrderId, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), customerDtls?.Mobile);
                            FCMModelData.Notification = string.Format(orderUpdateSMSMessage, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), orderData.OrderId, customerDtls?.Mobile, branchName);
                            FCMService.SaveFCMNotificationDrivers(FCMModelData);
                        }
                    }
                }
                modelData.OrderId = orderData.OrderId;
            }
            catch (Exception ex)
            {
            }
            return(bSuccess);
        }
Esempio n. 5
0
        public bool UpdateOrder(Model.Order modelData, string mailContent, string surgeryOrderMailContent, FCMNotificationModel FCMModelData)
        {
            bool bSuccess = false;

            try
            {
                if (modelData.OrderId > 0)
                {
                    ProOrder orderData = orderRepository.GetOrder(modelData.OrderId);
                    orderData.ModifiedOn         = DateTime.Now;
                    orderData.ModifiedBy         = userService.GetLoggdInUser().UserId;
                    orderData.OrderTypeId        = modelData.OrderTypeId;
                    orderData.IntervalCount      = modelData.IntervalCount;
                    orderData.DeliveryDate       = modelData.DeliveryDate;
                    orderData.PickupTypeId       = modelData.PickupTypeId;
                    orderData.IsStorageFridge    = modelData.IsStorageFridge;
                    orderData.IsControlledDrugs  = modelData.IsControlledDrugs;
                    orderData.OrderStatus        = modelData.OrderStatus;
                    orderData.RackNo             = modelData.RackNo;
                    orderData.RouteId            = modelData.RouteId;
                    orderData.CaseTypeId         = modelData.CaseTypeId;
                    orderData.RecentDeliveryNote = modelData.RecentDeliveryNote;
                    orderData.DeliveryNote       = modelData.DeliveryNote;
                    orderData.SurgeryNote        = modelData.SurgeryNote;
                    orderData.BranchNote         = modelData.BranchNote;
                    ProOrderDetail orderDetail;
                    orderData.ProOrderDetail = new List <ProOrderDetail>();
                    string emailItems = string.Empty;
                    foreach (var item in modelData.OrderDetails.Where(od => od.IsVisible).ToList())
                    {
                        if (!string.IsNullOrEmpty(item.MedicineName) && Converters.ConvertInt(item.Quantity) > 0)
                        {
                            orderDetail = new ProOrderDetail
                            {
                                ProductId     = item.ProductId,
                                Strength      = item.Strength,
                                Morning       = item.Morning,
                                AfterNoon     = item.AfterNoon,
                                Evening       = item.Evening,
                                Night         = item.Night,
                                Quantity      = item.Quantity,
                                Duration      = item.Duration,
                                Remarks       = item.Remarks,
                                OrderDetailId = item.OrderDetailId
                            };
                            orderData.ProOrderDetail.Add(orderDetail);
                            emailItems += $"<tr><td>{item.MedicineName}</td><td>{item.Duration}</td><td>{Converters.ConvertInt(item.Quantity)}</td></tr>";
                        }
                    }
                    bSuccess = orderRepository.SaveOrder(orderData, modelData);
                    if (bSuccess && modelData.OldOrderStatus != modelData.OrderStatus)
                    {
                        string branchName = orderData.BranchId.HasValue ? branchRepositry.GetBranch((long)orderData.BranchId).BranchName : string.Empty;
                        //Check customer has registered mobile  APP and application created with User for that customer
                        var    customerUserMapData   = userRepository.GetCustomerUserMap(orderData.CustomerId.Value);
                        string orderUpdateSMSMessage = messageTemplateService.GetMessageTemplate(orderData.CompanyId.Value, (long)orderData.BranchId, (int)MessageTypes.SMS, (int)MessageEvents.OrderUpdate);

                        if (customerUserMapData != null)
                        {
                            FCMModelData.UserId    = customerUserMapData.UserId;
                            FCMModelData.CompanyId = customerUserMapData.CompanyId;
                            FCMModelData.BranchId  = customerUserMapData.BranchId;
                            //FCMModelData.Notification = string.Format(ResourceService.Resource.GetMessage("NMOrderStatusChange"), orderData.OrderId, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()));
                            FCMModelData.Notification = string.Format(orderUpdateSMSMessage, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), orderData.OrderId, modelData.Customer.Mobile, branchName);
                            FCMService.SaveFCMNotificationUser(FCMModelData);
                        }

                        FCMModelData.CompanyId = orderData.CompanyId.Value;
                        FCMModelData.BranchId  = orderData.BranchId;
                        //FCMModelData.Notification = string.Format(ResourceService.Resource.GetMessage("NMOrderStatusChangeForDriver"), orderData.OrderId, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), modelData.Customer.Mobile);
                        FCMModelData.Notification = string.Format(orderUpdateSMSMessage, ResourceService.Resource.GetCaption(((OrderStatus)orderData.OrderStatus).ToString()), orderData.OrderId, modelData.Customer.Mobile, branchName);
                        FCMService.SaveFCMNotificationDrivers(FCMModelData);
                    }



                    if (bSuccess && modelData.ActionType.HasValue && modelData.ActionType.Value == 1)
                    {
                        var branchId     = userService.GetLoggdInUser().BranchId;
                        var customerDtls = customerService.GetCustomer(orderData.CustomerId.Value);
                        var branchDtls   = branchRepositry.GetBranch(branchId);
                        var branchInfo   = $@"<tr><td class='header-sm'>{branchDtls.BranchName}</td></tr><tr><td>{branchDtls.Address?.Address1}</td></tr><tr><td>{branchDtls.Address?.Address2}</td></tr>
                                                <tr><td>{branchDtls.Address.PostCode}</td></tr><tr><td>{branchDtls.Address.City}</td></tr>";

                        if (!string.IsNullOrEmpty(customerDtls?.Email))
                        {
                            mailContent = mailContent.Replace("$BRANCHDTLS$", branchInfo);
                            mailContent = mailContent.Replace("$CURRENTDATE$", DateTime.Now.ToString("dd MMMM yyyy"));
                            mailContent = mailContent.Replace("$PATIENTDTLS$", string.Concat(customerDtls.FirstName, " ", customerDtls.LastName, "  DOB:", customerDtls.Dob.ToShortDateString(), "  NHS NO:", customerDtls.NHSNumber.ToString()));
                            mailContent = mailContent.Replace("$ITEMLIST$", emailItems);
                            mailContent = mailContent.Replace("$REQUESTEDBY$", string.Concat(customerDtls.FirstName, " ", customerDtls.LastName, "  DOB:", customerDtls.Dob.ToShortDateString(), "  NHS NO:", customerDtls.NHSNumber.ToString()));
                            emailService.SendMail(new string[] { customerDtls.Email }, $"Order Updated [{orderData.OrderId}]", mailContent);
                        }
                        //if (Converters.ConvertInt(modelData.SurgeryId) > 0)
                        //{
                        //    var surgeryData = masterService.GetSurgery(modelData.SurgeryId.Value);
                        //    if (surgeryData != null && !string.IsNullOrEmpty(surgeryData.Email))
                        //    {
                        //        if (!string.IsNullOrEmpty(surgeryOrderMailContent))
                        //        {
                        //            surgeryOrderMailContent = surgeryOrderMailContent.Replace("$ITEMLIST$", emailItems);
                        //            emailService.SendMail(new string[] { surgeryData.Email.Trim() }, $"Order Created [{orderData.OrderId}]", surgeryOrderMailContent);
                        //        }
                        //    }
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
            }
            return(bSuccess);
        }
Esempio n. 6
0
 public bool SaveOrder(ProOrder orderData, Order modelData)
 {
     return(dbContext.SaveChanges() > 0);
 }