public ActionResult WorkingPlacePage(string id)
        {
            if (id == null || !id.IsInt())
            {
                return(RedirectToAction("FindWorkPlaces"));
            }

            WorkingPlaceModel modelPlace = Utilities.SendDbUtility.GetWorkingPlace(Int32.Parse(id));

            if (modelPlace == null)
            {
                return(RedirectToAction("FindWorkPlaces"));
            }

            SalonModel           modelSalon = Utilities.SendDbUtility.GetSalon(modelPlace.SalonId);
            List <TimeSlotModel> modelsTime = Utilities.SendDbUtility.GetTimeSlots(modelPlace.Id);

            if (modelSalon == null)
            {
                return(RedirectToAction("FindWorkPlaces"));
            }

            ViewBag.ErrorMessage = TempData["ErrorMessage"];
            ViewBag.InfoMessage  = TempData["InfoMessage"];

            bool isAdminOfSalon = false;
            int  userId         = 0;

            if (Request.Cookies.AllKeys.Contains("SalonId") && Request.Cookies["SalonId"].Value == modelPlace.SalonId.ToString() && Utilities.SendDbUtility.CheckAdmin(modelPlace.SalonId, User.Identity.Name))
            {
                isAdminOfSalon = true;
            }
            else
            {
                userId = Utilities.SendDbUtility.GetResidentId(User.Identity.Name);
            }

            ViewBag.Favorites = Utilities.SendDbUtility.CheckFavorite(modelPlace.Id, userId);

            ViewBag.IsAdminOfSalon = isAdminOfSalon;

            BookingModel modelBooking = new BookingModel()
            {
                PlaceId    = Int32.Parse(id),
                SalonId    = modelPlace.SalonId,
                ResidentId = userId
            };



            object[] x = new object[]
            {
                modelPlace,
                modelSalon,
                modelsTime,
                modelBooking
            };

            return(View(x));
        }
Пример #2
0
        public async Task <IActionResult> PutSalonModel(int id, SalonModel salonModel)
        {
            if (id != salonModel.masalon)
            {
                return(BadRequest());
            }

            _context.Entry(salonModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SalonModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <ActionResult <SalonModel> > PostSalonModel(SalonModel salonModel)
        {
            _context.salon.Add(salonModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSalonModel", new { id = salonModel.masalon }, salonModel));
        }
        public ActionResult <SalonModel> Post(SalonModel model)
        {
            try
            {
                var uri = _linkGenerator.GetPathByAction(HttpContext,
                                                         "Get",
                                                         values: new { name = model.SalonName });

                if (string.IsNullOrWhiteSpace(uri))
                {
                    return(BadRequest("Could not use current name"));
                }

                var salon = _repository.Create(model);
                if (_repository.SaveChangesAsync())
                {
                    return(Created(uri, _mapper.Map <SalonModel>(salon)));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
Пример #5
0
 public static SalonModel GetDataSalonAdmin(string Email)
 {
     using (UserContext DbUse = new UserContext())
     {
         SalonModel user = DbUse.SalonModels.FirstOrDefault(t => t.Email == Email);
         return(user);
     }
 }
Пример #6
0
 public ActionResult AddSalon(SalonModel model)
 {
     if (!ModelState.IsValid)
     {
         TempData["ErrorMessage"] = "Не заполнены все обязательные поля!";
         return(RedirectToAction("SalonShow"));
     }
     Utilities.SendDbUtility.AddSalon(model);
     return(RedirectToAction("SalonShow"));
 }
        public Salon Create(SalonModel model)
        {
            _logger.LogInformation("Create new Salon entity");
            Salon salon = new Salon
            {
                Name        = model.SalonName,
                Address     = model.SalonAddress,
                PhoneNumber = model.SalonPhoneNumber
            };

            _context.Add(salon);
            return(salon);
        }
Пример #8
0
 public static bool AddSalon(SalonModel model)
 {
     using (UserContext dbUse = new UserContext())
     {
         try
         {
             dbUse.SalonModels.Add(model);
             dbUse.SaveChanges();
         }
         catch (Exception e)
         {
             return(false);
         }
         return(true);
     }
 }
        public async Task <ActionResult <SalonModel> > Update(int id, SalonModel model)
        {
            try
            {
                var oldSalon = await _repository.GetSalonByIdAsync(id);

                var res = _mapper.Map(model, oldSalon);
                _repository.SaveChangesAsync();

                return(_mapper.Map <SalonModel>(res));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
Пример #10
0
 // Метод занесения данных салона в бд
 public static bool SendSalon(SalonModel model)
 {
     try
     {
         using (UserContext DbUse = new UserContext())
         {
             DbUse.SalonModels.Add(model);
             DbUse.SaveChanges();
         }
     }
     catch (Exception e)
     {
         return(true);
     }
     return(true);
 }
Пример #11
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var parameter = e.Parameter;

            Type type = e.Parameter?.GetType();

            if (type != null)
            {
                SalonModel model = (SalonModel)type.GetProperty("SalonModel").GetValue(parameter);
                Code      = model.Code;
                SalonName = model.Name;
                Location  = model.Location.Name;
                Manager   = model.Manager.Name;

                Serivces = new SalonControl().GetAllSalonServiceInfos(Code);
            }
        }
Пример #12
0
 public void LoadData(SalonModel salon)
 {
     try
     {
         if (salon != null)
         {
             Assets = new AssetsControl().GetAssets(salon.Code);
         }
         else
         {
             Assets = new ObservableCollection <AssetsModel>();
         }
     }
     catch (Exception ex)
     {
         AppLog.Error(typeof(AssetsEditViewModel), ex.ToString());
     }
 }
Пример #13
0
 public void LoadData(SalonModel salon)
 {
     try
     {
         if (salon != null)
         {
             _orders = new OrderControl().GetOrders(salon.Code);
         }
         else
         {
             _orders = new ObservableCollection <OrderModel>();
         }
     }
     catch (Exception ex)
     {
         AppLog.Error(typeof(CustomEditViewModel), ex.ToString());
     }
 }
Пример #14
0
        private void Load()
        {
            if (_salons == null)
            {
                //数据库检索
                _salons = new ObservableCollection <SalonModel>();
                using (DBConnect connect = new DBFactory().GetPostgreSQLDBConnect().StartConnect())
                {
                    var list = connect.FindAll <DBModels.PostgreSQL.Salon, int>(m => m.Id);

                    foreach (var item in list)
                    {
                        SalonModel model = new SalonModel();
                        ModelHelper.CopyModel(model, item);
                        _salons.Add(model);
                    }
                }
            }
        }
 public void LoadData(SalonModel salon)
 {
     try
     {
         if (salon != null)
         {
             StaffInfos = new StaffControl().GetStaffInfosBySalon(salon.Code);
             if (StaffInfos.Count > 0)
             {
                 StaffInfo = StaffInfos[0];
             }
         }
         else
         {
             StaffInfos.Clear();
         }
     }
     catch (Exception ex)
     {
         AppLog.Error(typeof(StaffOrderEditViewModel), ex.ToString());
     }
 }
Пример #16
0
        // Метод проверки введенного логина и пароля салона
        public static bool ComparePasswordSalon(string Password, string Email)
        {
            try
            {
                using (UserContext dbUse = new UserContext())
                {
                    //var hashPass = GetData.GetHash(Password);
                    SalonModel user =
                        dbUse.SalonModels.FirstOrDefault(t => t.Email == Email && t.AdminPass == Password);

                    if (user == null)
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #17
0
 public AppointmentsController(SalonModel context)
 {
     _context = context;
 }
Пример #18
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                string isError      = "";
                int    addedSlots   = 0;
                int    deletedSlots = 0;
                using (UserContext dbUse = new UserContext())
                {
                    try
                    {
                        IEnumerable <TimeSlotModel> slots = dbUse.TimeSlotModels.Where(t => t.Date < DateTime.Today);
                        dbUse.TimeSlotModels.RemoveRange(slots);
                        dbUse.BookingModels.RemoveRange(dbUse.BookingModels.Where(t => t.Date < DateTime.Today));
                        var lusd = slots.ToList();
                        deletedSlots = lusd.Count();
                        dbUse.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        isError = "Ошибка в удалении прошедших дат:\n" + e.ToString();
                    }
                }

                using (UserContext dbUse = new UserContext())
                {
                    try
                    {
                        List <WorkingPlaceModel> allPlaces = SendDbUtility.GetAllWorkingPlaces();

                        foreach (var place in allPlaces)
                        {
                            //SalonModel salon = SendDbUtility.GetSalon(place.SalonId);
                            //string[] workingTime = salon.OperatingMode.Split('-');
                            //int constFrom = Int32.Parse(workingTime[0].Trim().Substring(0, 2));
                            //int constTo = Int32.Parse(workingTime[1].Trim().Substring(0, 2));

                            //int from;
                            //int to;
                            //int tempTo;
                            //int tempFrom;
                            //DateTime dateNow = DateTime.Today;

                            //for (int i = 0; i < 14; i++)
                            //{

                            //    from = constFrom;
                            //    to = constTo;
                            //    while (from != to)
                            //    {
                            //        tempFrom = from;
                            //        tempTo = ++from;
                            //        string isExist = SendDbUtility.CheckTimeSlot(dateNow,
                            //            tempFrom.ToString() + ":00-" + tempTo.ToString() + ":00", place.Id);
                            //        if (isExist == "0")
                            //        {
                            //            dbUse.TimeSlotModels.Add(new TimeSlotModel()
                            //            {
                            //                PlaceId = place.Id,
                            //                SalonId = place.SalonId,
                            //                Time = tempFrom.ToString() + ":00-" + tempTo.ToString() + ":00",
                            //                Booked = false,
                            //                Date = dateNow
                            //            });
                            //            addedSlots++;
                            //        }
                            //        else if(isExist != "1")
                            //        {
                            //            isError = "Ошибка в проверке тайм слота:\n" + isExist;
                            //        }
                            //    }
                            //    dateNow = dateNow.AddDays(1);
                            //}



                            SalonModel salon          = SendDbUtility.GetSalon(place.SalonId);
                            string[]   workingTimeMon = salon.OperatingModeMon.Split('-');
                            int        constFromMon   = Int32.Parse(workingTimeMon[0].Trim().Substring(0, 2));
                            int        constToMon     = Int32.Parse(workingTimeMon[1].Trim().Substring(0, 2));

                            string[] workingTimeTue = salon.OperatingModeTue.Split('-');
                            int      constFromTue   = Int32.Parse(workingTimeTue[0].Trim().Substring(0, 2));
                            int      constToTue     = Int32.Parse(workingTimeTue[1].Trim().Substring(0, 2));

                            string[] workingTimeWed = salon.OperatingModeWed.Split('-');
                            int      constFromWed   = Int32.Parse(workingTimeWed[0].Trim().Substring(0, 2));
                            int      constToWed     = Int32.Parse(workingTimeWed[1].Trim().Substring(0, 2));

                            string[] workingTimeThu = salon.OperatingModeThu.Split('-');
                            int      constFromThu   = Int32.Parse(workingTimeThu[0].Trim().Substring(0, 2));
                            int      constToThu     = Int32.Parse(workingTimeThu[1].Trim().Substring(0, 2));

                            string[] workingTimeFri = salon.OperatingModeFri.Split('-');
                            int      constFromFri   = Int32.Parse(workingTimeFri[0].Trim().Substring(0, 2));
                            int      constToFri     = Int32.Parse(workingTimeFri[1].Trim().Substring(0, 2));

                            string[] workingTimeSat = salon.OperatingModeSat.Split('-');
                            int      constFromSat   = Int32.Parse(workingTimeSat[0].Trim().Substring(0, 2));
                            int      constToSat     = Int32.Parse(workingTimeSat[1].Trim().Substring(0, 2));

                            string[] workingTimeSun = salon.OperatingModeSun.Split('-');
                            int      constFromSun   = Int32.Parse(workingTimeSun[0].Trim().Substring(0, 2));
                            int      constToSun     = Int32.Parse(workingTimeSun[1].Trim().Substring(0, 2));

                            if (constFromMon > constToMon)
                            {
                                constFromMon = constToMon;
                            }
                            if (constFromTue > constToTue)
                            {
                                constFromTue = constToTue;
                            }
                            if (constFromWed > constToWed)
                            {
                                constFromWed = constToWed;
                            }
                            if (constFromThu > constToThu)
                            {
                                constFromThu = constToThu;
                            }
                            if (constFromFri > constToFri)
                            {
                                constFromFri = constToFri;
                            }


                            if (constFromSat > constToSat)
                            {
                                constFromSat = constToSat;
                            }
                            if (constFromSun > constToSun)
                            {
                                constFromSun = constToSun;
                            }
                            int      from;
                            int      to;
                            int      tempTo;
                            int      tempFrom;
                            DateTime dateNow = DateTime.Today;
                            for (int i = 0; i < 14; i++)
                            {
                                if (dateNow.DayOfWeek == DayOfWeek.Saturday)
                                {
                                    from = constFromSat;
                                    to   = constToSat;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Sunday)
                                {
                                    from = constFromSun;
                                    to   = constToSun;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Monday)
                                {
                                    from = constFromMon;
                                    to   = constToMon;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Tuesday)
                                {
                                    from = constFromTue;
                                    to   = constToTue;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Wednesday)
                                {
                                    from = constFromWed;
                                    to   = constToWed;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Thursday)
                                {
                                    from = constFromThu;
                                    to   = constToThu;
                                }
                                else if (dateNow.DayOfWeek == DayOfWeek.Friday)
                                {
                                    from = constFromFri;
                                    to   = constToFri;
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }
                                while (from != to)
                                {
                                    tempFrom = from;
                                    tempTo   = ++from;

                                    string isExist = SendDbUtility.CheckTimeSlot(dateNow,
                                                                                 tempFrom.ToString() + ":00-" + tempTo.ToString() + ":00", place.Id);
                                    if (isExist == "0")
                                    {
                                        dbUse.TimeSlotModels.Add(new TimeSlotModel()
                                        {
                                            PlaceId = place.Id,
                                            SalonId = place.SalonId,
                                            Time    = tempFrom.ToString() + ":00-" + tempTo.ToString() + ":00",
                                            Booked  = false,
                                            Date    = dateNow
                                        });
                                        addedSlots++;
                                    }
                                    else if (isExist != "1")
                                    {
                                        isError = "Ошибка в проверке тайм слота:\n" + isExist;
                                    }
                                }

                                dateNow = dateNow.AddDays(1);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        isError = "Ошибка в добавлении новых дат:\n" + e.ToString();
                    }
                    if (isError != "")
                    {
                        WriteLogs(isError);
                        await Execute(context);
                    }
                    else
                    {
                        dbUse.SaveChanges();
                        WriteLogs("Обновление прошло успешно \nУдалено " + deletedSlots + " слотов \nДобавлено " + addedSlots + " слотов");
                    }
                }
            }
            catch (Exception e)
            {
                WriteLogs("Глобальная ошибка обновления");
            }
        }
 public ActionResult RegisterSalon(SalonModel model)
 {
     Utilities.SendDbUtility.SendSalon(model);
     return(RedirectToAction("SalonManage", "Admin"));
 }
        public ActionResult ShowBookedResidents()
        {
            if (!Request.Cookies.AllKeys.Contains("SalonId"))
            {
                return(RedirectToAction("MainPage"));
            }
            int salonId = Int32.Parse(Server.UrlDecode(Request.Cookies["SalonId"].Value));

            if (!Utilities.SendDbUtility.CheckAdmin(salonId, User.Identity.Name))
            {
                return(RedirectToAction("MainPage"));
            }



            //List<BookingModel> bookings = Utilities.SendDbUtility.GetBookingForSalonId(salonId);
            //List<ResidentModel> residents = new List<ResidentModel>();
            //foreach (var a in residents)
            //{
            //    List<BookingModel> timeslots = Utilities.SendDbUtility.GetBooking(a.Id);
            //}


            //foreach (var booking in bookings)
            //{
            //    residents.AddRange(allResidents.Where(t=>t.Id == booking.ResidentId));
            //}


            SalonModel salon = Utilities.SendDbUtility.GetSalon(salonId);

            if (salon == null)
            {
                return(RedirectToAction("MainPage"));
            }
            List <List <int> > workingTimes = new List <List <int> >();

            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeSun.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeSun.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeMon.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeMon.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeTue.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeTue.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeWed.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeWed.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeThu.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeThu.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeFri.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeFri.Split('-')[1].Split(':')[0]) + 1
            });
            workingTimes.Add(new List <int>()
            {
                Int32.Parse(salon.OperatingModeSat.Split('-')[0].Split(':')[0]), Int32.Parse(salon.OperatingModeSat.Split('-')[1].Split(':')[0]) + 1
            });
            foreach (var times in workingTimes)
            {
                if (times[1] - times[0] == 1)
                {
                    times[1] = times[0];
                }
            }

            List <WorkingPlaceModel> places = Utilities.SendDbUtility.GetWorkingPlaces(salonId);


            List <BookingModel> bookings = Utilities.SendDbUtility.GetBookingForSalonId(salonId);

            List <ResidentModel> allResidents = Utilities.SendDbUtility.GetAllResidents();

            object[] x = new object[]
            {
                //bookings,
                //allResidents
                workingTimes,
                places,
                bookings,
                allResidents
            };

            // AdminBookingModel model = new AdminBookingModel();

            //model.JobPlaceId =  Int32.Parse(Request.Cookies["SalonId"].Value);

            // int SalonIdAdmin = Int32.Parse(Request.Cookies["SalonId"].Value);

            // // получаем список рабочих мест по айди из куки
            // model.bookingTimeList = Utilities.SendDbUtility.GetWorkingPlaces(SalonIdAdmin);



            //foreach (var f in model.bookingTimeList)
            //{
            //  model.TimeSlotAdmin.AddRange(Utilities.SendDbUtility.GetTimeSlots(f.Id));

            //}



            return(View(x));
        }
 public PetsController(SalonModel context)
 {
     _context = context;
 }
        public ActionResult Booking(BookingModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request.Cookies.AllKeys.Contains("SalonId"))
                {
                    if (Request.Cookies["SalonId"].Value != model.SalonId.ToString())
                    {
                        TempData["ErrorMessage"] = "Ошибка бронирования.";
                        return(RedirectToAction("WorkingPlacePage", "TimerClub", new { id = model.PlaceId.ToString() }));
                    }

                    if (model.Name == "" || model.Surname == "" || model.Phone == "")
                    {
                        TempData["ErrorMessage"] = "Введите имя, фамилию и телефон мастера";
                        return(RedirectToAction("WorkingPlacePage", "TimerClub", new { id = model.PlaceId.ToString() }));
                    }
                }

                var timesCount          = model.Times.Split(';').Length - 1;
                WorkingPlaceModel place = Utilities.SendDbUtility.GetWorkingPlace(model.PlaceId);
                SalonModel        salon = Utilities.SendDbUtility.GetSalon(place.SalonId);
                string[]          times = new string[] {};
                if (model.Date.DayOfWeek == DayOfWeek.Saturday)
                {
                    times = salon.OperatingModeSat.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Sunday)
                {
                    times = salon.OperatingModeSun.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Monday)
                {
                    times = salon.OperatingModeMon.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Tuesday)
                {
                    times = salon.OperatingModeTue.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Wednesday)
                {
                    times = salon.OperatingModeWed.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Thursday)
                {
                    times = salon.OperatingModeThu.Split('-');
                }
                else if (model.Date.DayOfWeek == DayOfWeek.Friday)
                {
                    times = salon.OperatingModeFri.Split('-');
                }
                else
                {
                    TempData["ErrorMessage"] = "Ошибка бронирования!";
                    return(RedirectToAction("WorkingPlacePage", "TimerClub", new { id = model.PlaceId }));
                }

                if (times.Length != 2)
                {
                    TempData["ErrorMessage"] = "Ошибка бронирования!";
                    return(RedirectToAction("WorkingPlacePage", "TimerClub", new { id = model.PlaceId }));
                }
                int    fullDayCount = Int32.Parse(times[1].Split(':')[0]) - Int32.Parse(times[0].Split(':')[0]);
                double total;
                if (timesCount >= fullDayCount && place.RateDay != 0)
                {
                    total = place.RateDay;
                }
                else
                {
                    total = timesCount * place.Rate1h;
                }

                model.Sum = total;


                if (!Utilities.SendDbUtility.SetBooking(model))
                {
                    TempData["ErrorMessage"] = "Ошибка бронирования!";
                }
                else
                {
                    TempData["InfoMessage"] = "Рабочее место успешно забронировано!";
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Не все обязательные поля заполнены!";
            }
            return(RedirectToAction("WorkingPlacePage", "TimerClub", new { id = model.PlaceId }));
        }
Пример #23
0
        public static bool SetBooking(BookingModel model)
        {
            using (UserContext dbUse = new UserContext())
            {
                try
                {
                    List <BookingModel> bookings = dbUse.BookingModels.ToList();
                    foreach (var book in bookings)
                    {
                        bool     flagBooked = false;
                        string[] bookTimes  = book.Times.Split(';');
                        for (int i = 0; i < bookTimes.Length - 1; i++)
                        {
                            if (model.Times.Contains(bookTimes[i]))
                            {
                                flagBooked = true;
                                break;
                            }
                        }

                        if ((book.PlaceId == model.PlaceId) && (book.Date == model.Date) && (flagBooked))
                        {
                            return(false);
                        }
                    }
                    SalonModel salon = GetSalon(model.SalonId);
                    if (salon.ReservationType)
                    {
                        model.Confirmed = false;
                    }
                    else
                    {
                        model.Confirmed = true;
                    }
                    BookingModel booking = dbUse.BookingModels.Add(model);

                    dbUse.SaveChanges();

                    string[]      times = model.Times.Split(';');
                    TimeSlotModel timeSlot;
                    string        chosenTime;
                    for (int i = 0; i < times.Length - 1; i++)
                    {
                        chosenTime = times[i];
                        timeSlot   = dbUse.TimeSlotModels.FirstOrDefault(t =>
                                                                         ((t.Time == chosenTime) && (t.Date == model.Date) && (t.PlaceId == model.PlaceId)));
                        if (timeSlot.Booked || timeSlot == null)
                        {
                            return(false);
                        }
                        timeSlot.ResidentId = model.ResidentId;
                        timeSlot.Booked     = true;
                        timeSlot.BookingId  = booking.Id;
                        dbUse.TimeSlotModels.AddOrUpdate(timeSlot);
                    }



                    dbUse.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Пример #24
0
        public static bool AddWorkingPlace(WorkingPlaceModel model)
        {
            using (UserContext dbUse = new UserContext())
            {
                try
                {
                    dbUse.WorkingPlaceModels.Add(model);
                    dbUse.SaveChanges();

                    SalonModel salon          = GetSalon(model.SalonId);
                    string[]   workingTimeMon = salon.OperatingModeMon.Split('-');
                    int        constFromMon   = Int32.Parse(workingTimeMon[0].Trim().Substring(0, 2));
                    int        constToMon     = Int32.Parse(workingTimeMon[1].Trim().Substring(0, 2));

                    string[] workingTimeTue = salon.OperatingModeTue.Split('-');
                    int      constFromTue   = Int32.Parse(workingTimeTue[0].Trim().Substring(0, 2));
                    int      constToTue     = Int32.Parse(workingTimeTue[1].Trim().Substring(0, 2));

                    string[] workingTimeWed = salon.OperatingModeWed.Split('-');
                    int      constFromWed   = Int32.Parse(workingTimeWed[0].Trim().Substring(0, 2));
                    int      constToWed     = Int32.Parse(workingTimeWed[1].Trim().Substring(0, 2));

                    string[] workingTimeThu = salon.OperatingModeThu.Split('-');
                    int      constFromThu   = Int32.Parse(workingTimeThu[0].Trim().Substring(0, 2));
                    int      constToThu     = Int32.Parse(workingTimeThu[1].Trim().Substring(0, 2));

                    string[] workingTimeFri = salon.OperatingModeFri.Split('-');
                    int      constFromFri   = Int32.Parse(workingTimeFri[0].Trim().Substring(0, 2));
                    int      constToFri     = Int32.Parse(workingTimeFri[1].Trim().Substring(0, 2));

                    string[] workingTimeSat = salon.OperatingModeSat.Split('-');
                    int      constFromSat   = Int32.Parse(workingTimeSat[0].Trim().Substring(0, 2));
                    int      constToSat     = Int32.Parse(workingTimeSat[1].Trim().Substring(0, 2));

                    string[] workingTimeSun = salon.OperatingModeSun.Split('-');
                    int      constFromSun   = Int32.Parse(workingTimeSun[0].Trim().Substring(0, 2));
                    int      constToSun     = Int32.Parse(workingTimeSun[1].Trim().Substring(0, 2));
                    if (constFromMon > constToMon)
                    {
                        constFromMon = constToMon;
                    }
                    if (constFromTue > constToTue)
                    {
                        constFromTue = constToTue;
                    }
                    if (constFromWed > constToWed)
                    {
                        constFromWed = constToWed;
                    }
                    if (constFromThu > constToThu)
                    {
                        constFromThu = constToThu;
                    }
                    if (constFromFri > constToFri)
                    {
                        constFromFri = constToFri;
                    }


                    if (constFromSat > constToSat)
                    {
                        constFromSat = constToSat;
                    }
                    if (constFromSun > constToSun)
                    {
                        constFromSun = constToSun;
                    }

                    int      from;
                    int      to;
                    int      tempTo;
                    int      tempFrom;
                    DateTime dateNow = DateTime.Today;
                    for (int i = 0; i < 14; i++)
                    {
                        if (dateNow.DayOfWeek == DayOfWeek.Saturday)
                        {
                            from = constFromSat;
                            to   = constToSat;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Sunday)
                        {
                            from = constFromSun;
                            to   = constToSun;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Monday)
                        {
                            from = constFromMon;
                            to   = constToMon;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Tuesday)
                        {
                            from = constFromTue;
                            to   = constToTue;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Wednesday)
                        {
                            from = constFromWed;
                            to   = constToWed;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Thursday)
                        {
                            from = constFromThu;
                            to   = constToThu;
                        }
                        else if (dateNow.DayOfWeek == DayOfWeek.Friday)
                        {
                            from = constFromFri;
                            to   = constToFri;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                        while (from != to)
                        {
                            tempFrom = from;
                            tempTo   = ++from;
                            dbUse.TimeSlotModels.Add(new TimeSlotModel()
                            {
                                PlaceId = model.Id,
                                SalonId = model.SalonId,
                                Time    = tempFrom.ToString() + ":00-" + tempTo.ToString() + ":00",
                                Booked  = false,
                                Date    = dateNow
                            });
                        }

                        dateNow = dateNow.AddDays(1);
                    }
                    dbUse.SaveChanges();
                }
                catch (Exception e)
                {
                    return(false);
                }
                return(true);
            }
        }