Example #1
0
 public InvoiceGetAllResponse InvoicesGetAllByFilter(InvoiceGetAllRequest request)
 {
     return(Execute <InvoiceGetAllRequest, InvoiceGetAllResponse>(
                request,
                response =>
     {
         int totalCount;
         response.Invoices = MealMenuOrderFacade.GetInvoicesByFilter(request.Filter, request.PageSize, request.PageIndex,
                                                                     request.OrderByField, request.OrderByAsc, out totalCount);
         response.TotalCount = totalCount;
     }));
 }
Example #2
0
        public MealMenuOrderItemSaveResponse SaveOrderItem(MealMenuOrderItemSaveRequest request)
        {
            return(Execute <MealMenuOrderItemSaveRequest, MealMenuOrderItemSaveResponse>(
                       request,
                       response =>
            {
                var annualAgreements = SchoolFacade.AnnualAgreementsByFilter(request.SchoolId, DateTime.Now.Year, request.MealTypeId);
                response.OrderItem = MealMenuOrderFacade.SaveOrderItem(request.OrderItem, request.SchoolId, annualAgreements.FirstOrDefault().Value);

                //if (request.OrderItem.Id > 0 && request.SchoolId>0)
                if (request.OrderItem.Id > 0 && request.SchoolId > 0 && (response.OrderItem.RefId ?? 0) > 0)
                {
                    int totalCount;
                    var invoice = MealMenuOrderFacade
                                  .GetInvoicesByFilter(new InvoiceFilterView
                    {
                        OrderDate = new DateTime(response.OrderItem.MealMenuValidDate.Year, response.OrderItem.MealMenuValidDate.Month, 1),
                        SchoolId = request.SchoolId,
                        RecordCount = 1
                    }, 1, 1, "", false, out totalCount).FirstOrDefault();
                    if (invoice == null || invoice.OrderStatus.Id == (long)OrderStatuses.InitialState)
                    {
                        return;
                    }
                    var orderItem = response.OrderItem;
                    var mailAddress = Settings.GetSetting <string>("EmailContactRegardsTo");
                    var school = SchoolFacade.Get(request.SchoolId);
                    // var emails = school.Users.Select(k => k.UserName).ToList();
                    var emails = new List <string>();
                    // UserFacade.GetActiveSchoolUsers(request.SchoolId).Select(c => c.UserName).ToList();
                    emails.Insert(0, mailAddress);
                    var toEmails = string.Join(",", emails);
                    var changedList = MealMenuOrderFacade.GetOrderItemHistory(response.OrderItem.RefId ?? 0);
                    var body = new StringBuilder();
                    body.AppendLine(
                        string.Format("<br/>{0} menu updates occured in {1} - {2} school {3} date order",
                                      orderItem.MenuName, school.Code, school.Name, orderItem.MealMenuValidDate));
                    changedList.ForEach(
                        d => body.AppendLine(string.Format("<br/><br/>Date : {0}", d.ModifiedAt))
                        .AppendLine(string.Format("<br/>Count : {0}", d.TotalCount))
                        .AppendLine(string.Format("<br/>Modified By : {0}", d.ModifiedByFullName))
                        .AppendLine(string.Format("<br/>Reason : {0}", d.ModifiedReason))
                        .AppendLine().AppendLine());

                    var subject = string.Format("{0} - {1} school {2} order {3} Menu Updates", school.Code,
                                                school.Name, orderItem.MealMenuValidDate, orderItem.MenuName);

                    MailService.SendMail(toEmails, subject, body.ToString());
                }
            }));
        }
Example #3
0
        public SaveOrderForDayResponse SaveOrderForDay(SaveOrderForDayRequest request)
        {
            return(Execute <SaveOrderForDayRequest, SaveOrderForDayResponse>(
                       request,
                       response =>
            {
                var isUpdated = request.Day.Items.Any(d => d.Id > 0);
                var currentUser = Thread.CurrentPrincipal.AsCurrentUser();
                request.Day.Items.ForEach(d =>
                {
                    d.ModifiedBy = currentUser.Name;
                    d.ModifiedByFullName = currentUser.FullName;
                    d.ModifiedReason = (currentUser.UserTypeId() == (int)UserTypes.Company)?"Modified By Company":String.Empty;
                });

                var annualAgreements = SchoolFacade.AnnualAgreementsByFilter(request.Day.SchoolId, DateTime.Now.Year, request.Day.MealTypeId);
                request.Day.OrderRate = annualAgreements.FirstOrDefault().Value;
                response.Day = MealMenuOrderFacade.SaveOrderForDay(request.Day);

                var mailAddress = Settings.GetSetting <string>("EmailContactRegardsTo");
                var school = SchoolFacade.Get(request.Day.SchoolId);
                var emails = new List <string>();
                emails.Insert(0, mailAddress);
                var toEmails = string.Join(",", emails);
                var body = new StringBuilder();

                if (isUpdated && currentUser.UserTypeId() == (int)UserTypes.School)
                {
                    int totalCount;
                    var invoice = MealMenuOrderFacade
                                  .GetInvoicesByFilter(new InvoiceFilterView
                    {
                        OrderDate = new DateTime(response.Day.Date.Year, response.Day.Date.Month, 1),
                        SchoolId = request.Day.SchoolId,
                        RecordCount = 1
                    }, 1, 1, "", false, out totalCount).FirstOrDefault();
                    if (invoice == null || invoice.OrderStatus.Id == (long)OrderStatuses.InitialState)
                    {
                        return;
                    }


                    body.AppendLine(
                        string.Format("<br/>Updates occured in {0} - {1} school {2} date order",
                                      school.Code, school.Name, response.Day.Date));
                    response.Day.Items.ForEach(d =>
                                               body.AppendLine(string.Format("<br/><br/>Menu : {0}", d.MenuName))
                                               .AppendLine(string.Format("<br/><br/>Date : {0}", d.ModifiedAt))
                                               .AppendLine(string.Format("<br/>Count : {0}", d.Count))
                                               .AppendLine(string.Format("<br/>Modified By : {0}", d.ModifiedByFullName))
                                               .AppendLine(string.Format("<br/>Reason : {0}", d.ModifiedReason))
                                               .AppendLine().AppendLine()
                                               );
                    var subject = string.Format("{0} - {1} school {2} order updates", school.Code,
                                                school.Name, request.Day.Date);

                    MailService.SendMail(toEmails, subject, body.ToString());
                }

                var fruitCount = request.Day.Items.Where(d => d.HasAdditionalFruit).Sum(d => d.Count);
                var vegetableCount = request.Day.Items.Where(d => d.HasAdditionalVegetable).Sum(d => d.Count);
                if (fruitCount > (request.Day.FruitCount * 1.25) || vegetableCount > (request.Day.VegetableCount * 1.25))
                {
                    body.Length = 0;

                    body.AppendLine(string.Format("<br/>Fruit/Vegetable count exceeded the threshold value in {0} - {1} school {2} date order",
                                                  school.Code, school.Name, response.Day.Date));
                    response.Day.Items.ForEach(d =>
                                               body.AppendLine(string.Format("<br/><br/>Fruit Count: {0}, Treshhold Value: {1}*1.25", fruitCount, request.Day.FruitCount))
                                               .AppendLine(string.Format("<br/><br/>Vegetable Count: {0}, Treshhold Value: {1}*1.25", vegetableCount, request.Day.VegetableCount))
                                               .AppendLine().AppendLine()
                                               );
                    var subject = string.Format("{0} - {1} school {2} order updates", school.Code,
                                                school.Name, request.Day.Date);

                    MailService.SendMail(toEmails, subject, body.ToString());
                }
            }));
        }