Exemplo n.º 1
0
        public async Task <IActionResult> PostAsync([FromForm] BussinessViewModel model)
        {
            string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            var addBussiness = await _bussinessService.AddBussinessAsync(model.Code, model.Name, model.Address, model.PhoneNumber, model.Email, model.Owner, model.OwnerPhone, userId);

            if (addBussiness != null)
            {
                return(Ok(new OperationResponse <Bussiness>
                {
                    IsSuccess = true,
                    Message = $"{addBussiness.Name} has been added successfully!",
                    Record = addBussiness
                }));
            }
            return(BadRequest(new OperationResponse <Bussiness>
            {
                Message = "Something went wrong",
                IsSuccess = true
            }));
        }
Exemplo n.º 2
0
        public ActionResult BussinessCalculator(BussinessViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!model.FirstDate.All(char.IsDigit) || !(Convert.ToInt16(model.FirstDate) > 0) || !(Convert.ToInt16(model.FirstDate) <= 31) ||
                    !model.SecondDate.All(char.IsDigit) || !(Convert.ToInt16(model.SecondDate) > 0) || !(Convert.ToInt16(model.SecondDate) <= 31))
                {
                    ModelState.AddModelError("", "Date should be between 1 to 31.");
                }
                if (!model.FirstMonth.All(char.IsDigit) || !(Convert.ToInt16(model.FirstMonth) > 0) || !(Convert.ToInt16(model.FirstMonth) <= 12) ||
                    !model.SecondMonth.All(char.IsDigit) || !(Convert.ToInt16(model.SecondMonth) > 0) || !(Convert.ToInt16(model.SecondMonth) <= 12))
                {
                    ModelState.AddModelError("", "Month should be between 1 to 12.");
                }
                if (!model.FirstYear.All(char.IsDigit) || !(Convert.ToInt16(model.FirstYear) > 1952) || !(Convert.ToInt16(model.FirstYear) <= 2099) ||
                    !model.SecondYear.All(char.IsDigit) || !(Convert.ToInt16(model.SecondYear) > 1952) || !(Convert.ToInt16(model.SecondYear) <= 2099))
                {
                    ModelState.AddModelError("", "Please enter valid year");
                }

                DateTime startDateTime, endDateTime;
                if (!DateTime.TryParse(model.FirstYear + "-" + model.FirstMonth + "-" + model.FirstDate, out startDateTime))
                {
                    ModelState.AddModelError("", "Please enter valid start date");
                }
                if (!DateTime.TryParse(model.SecondYear + "-" + model.SecondMonth + "-" + model.SecondDate, out endDateTime))
                {
                    ModelState.AddModelError("", "Please enter valid end date");
                }

                if (ModelState.IsValid)
                {
                    if (startDateTime > endDateTime)
                    {
                        ModelState.AddModelError("", "Oops! First date should not be greater than second date");
                    }

                    if (ModelState.IsValid)
                    {
                        model.HasResult = true;

                        TimeSpan duratioDateTime = (endDateTime - startDateTime);
                        if (model.IncludeEndDate)
                        {
                            duratioDateTime = duratioDateTime.Add(new TimeSpan(1, 0, 0, 0));
                        }
                        model.StartDate = startDateTime;
                        model.EndDate   = endDateTime;

                        if ((model.ResultRefineOption.Equals("exclude") && model.Option.Equals("nodays")) || (model.ResultRefineOption.Equals("includeonly") && model.Option.Equals("alldays")))
                        {
                            model.Days          = duratioDateTime.TotalDays;
                            model.Hours         = duratioDateTime.TotalHours;
                            model.Minutes       = duratioDateTime.TotalMinutes;
                            model.Seconds       = duratioDateTime.TotalSeconds;
                            model.Weeks         = string.Format("{0} Week(s) and {1} Day(s)", Math.Floor(model.Days / 7), (model.Days % 7));
                            model.LongDurations = DaysToMonthsYear(endDateTime, startDateTime, model.IncludeEndDate);
                            return(View(model));
                        }

                        if (model.ResultRefineOption.Equals("exclude") && model.Option.Equals("weekends"))
                        {
                            double daysCount = duratioDateTime.TotalDays;
                            for (DateTime date = model.StartDate; date <= model.EndDate; date = date.AddDays(1))
                            {
                                if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                                {
                                    daysCount -= 1;
                                }
                            }
                            TimeSpan duration = TimeSpan.FromDays(daysCount);
                            model.Days          = duration.TotalDays;
                            model.Hours         = duration.TotalHours;
                            model.Minutes       = duration.TotalMinutes;
                            model.Seconds       = duration.TotalSeconds;
                            model.Weeks         = string.Format("{0} Week(s) and {1} Day(s)", Math.Floor(model.Days / 7), (model.Days % 7));
                            model.LongDurations = DaysToMonthYearMaths(model.Days);
                            return(View(model));
                        }
                        if (model.ResultRefineOption.Equals("includeonly") && model.Option.Equals("weekends"))
                        {
                            double daysCount = 0;
                            for (DateTime date = model.StartDate; date <= model.EndDate; date = date.AddDays(1))
                            {
                                if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                                {
                                    daysCount += 1;
                                }
                            }
                            TimeSpan duration = TimeSpan.FromDays(daysCount);
                            model.Days          = duration.TotalDays;
                            model.Hours         = duration.TotalHours;
                            model.Minutes       = duration.TotalMinutes;
                            model.Seconds       = duration.TotalSeconds;
                            model.Weeks         = string.Format("{0} Week(s) and {1} Day(s)", Math.Floor(model.Days / 7), (model.Days % 7));
                            model.LongDurations = DaysToMonthYearMaths(model.Days);
                            return(View(model));
                        }
                        ModelState.AddModelError("", "You have selected wrong options.");
                        if (!ModelState.IsValid)
                        {
                            return(View(new BussinessViewModel()
                            {
                                HasResult = false
                            }));
                        }
                    }
                }
                return(View(new BussinessViewModel()
                {
                    HasResult = false
                }));
            }
            return(View(new BussinessViewModel()
            {
                HasResult = false
            }));
        }