Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Address,DistrictId,AcademyCategoryId,SupportNumber,Id,Name,Password,PhoneNubmber,AllowActivity,ContractorId,AcademyPercent")] Academy academy)
        {
            if (id != academy.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(academy);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AcademyExists(academy.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AcademyCategoryId"] = new SelectList(_context.AcademyCategories, "Id", "Name", academy.AcademyCategoryId);
            ViewData["DistrictId"]        = new SelectList(_context.Districts, "Id", "Name", academy.DistrictId);
            ViewData["ContractorId"]      = new SelectList(_context.Contractors, "Id", "FullName", academy.ContractorId);

            return(View(academy));
        }
Пример #2
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,DriverId,TaxiCabState,DriverPercent,ServiceType")] TaxiService taxiService)
        {
            if (id != taxiService.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(taxiService);
                    if (taxiService.TaxiCabState == TaxiCabState.Ready)
                    {
                        var passengers = _context.TaxiServices.Include(c => c.Passnegers).FirstOrDefault(c => c.Id == taxiService.Id)?.Passnegers;
                        foreach (var item in passengers)
                        {
                            item.RequsetState = RequsetSate.Servicing;
                            _context.Update(item);
                        }
                    }
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    throw ex;
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited().Where(c => c.ContractorId == User.GetContractor().Id), "Id", "Name", taxiService.DriverId);
            return(View(taxiService));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("DriverID,DriverPassport,DriverName,DriverBirth,DriverTel")] Driver driver)
        {
            if (id != driver.DriverID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(driver);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DriverExists(driver.DriverID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(driver));
        }
Пример #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ClientTel,ClientName,ClientBirth")] Client client)
        {
            if (id != client.ClientID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.ClientID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(client));
        }
Пример #5
0
        //تغییر وضعیت درخواست
        public async Task <IActionResult> ChangeState(string id, RequsetSate requsetSate)
        {
            var serviceRequset = await _context.ServiceRequsets
                                 .Include(c => c.Academy)
                                 .FirstOrDefaultAsync(m => m.Id == id && m.Academy.ContractorId == User.GetContractor().Id);

            if (serviceRequset == null || serviceRequset.RequsetState == RequsetSate.AwaitingAcademy)
            {
                return(NotFound());
            }
            try
            {
                if (requsetSate == RequsetSate.AwaitingAcademy)
                {
                    ViewBag.msg = "ثبت این وضعیت به عهده مدرسه است";
                    return(View(serviceRequset));
                }
                serviceRequset.RequsetState = requsetSate;
                _context.Update(serviceRequset);
                await _context.SaveChangesWithHistoryAsync(HttpContext);

                ViewBag.msg = "تغییر وضعیت با موفقیت انجام شد";
                return(View(serviceRequset));
            }
            catch (DbUpdateException ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Age,Password,PhoneNubmber,Age,Email,AllowActivity,RegisterCompanyNumber,RelaseDate,ExpireDate")] Contractor contractor)
        {
            if (id != contractor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contractor);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContractorExists(contractor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contractor));
        }
Пример #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CityId,DistrictPercent")] District district)
        {
            if (id != district.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(district);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DistrictExists(district.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", district.CityId);
            return(View(district));
        }
Пример #8
0
        public async Task <IActionResult> ChangeState([FromBody] ChangestateViewModel model)
        {
            try
            {
                #region بررسی اعتبار درخواست کننده
                var taxtiCab = await _context.TaxiServices.Undelited().FirstOrDefaultAsync(c => c.Id == model.TaxiCabId);

                if (taxtiCab == null || taxtiCab.DriverId != model.DriverId)
                {
                    await _logger.LogAsync(HttpContext, $"{nameof(taxtiCab)} Is NULL");

                    return(Ok(new ResultContract <bool>()
                    {
                        statuse = false, Data = false, message = "مشکلی بوجود آمد"
                    }));
                }
                #endregion

                var Service = await _context.ServiceRequsets.Include(c => c.StudentParent).FirstOrDefaultAsync(c => c.Id == model.RequseteId);

                if (Service == null)
                {
                    await _logger.LogAsync(HttpContext, $"{nameof(Service)} Is NULL");

                    return(Ok(new ResultContract <bool>()
                    {
                        statuse = false, Data = false, message = "مشکلی بوجود آمد"
                    }));
                }

                Service.NotifState = model.NotifState;
                _context.Update(Service);
                await _context.SaveChangesAsync();

                var    number = Service.StudentParent.PhoneNubmber;
                string token  = Service.Id;
                if (model.NotifState == NotifState.GetOn)
                {
                    await _notify.SendNotifyWithTemplateAsync(number, token, MessageTemplate.Bistrogetoff);
                }
                else
                {
                    await _notify.SendNotifyWithTemplateAsync(number, token, MessageTemplate.Bistogeton);
                }

                return(Ok(new ResultContract <bool>()
                {
                    statuse = true, Data = true
                }));
            }
            catch (Exception ex)
            {
                await _logger.LogAsync(HttpContext, ex);

                return(Ok(new ResultContract <bool>()
                {
                    statuse = false, Data = false, message = "مشکلی بوجود آمد"
                }));
            }
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,CityPercent")] City city)
        {
            if (id != city.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
Пример #10
0
        //Rate
        public void Rating(Order orderParams)
        {
            var order = _context.Orders.Find(orderParams.OrderId);

            if (order.CustomerId != orderParams.CustomerId)
            {
                throw new AppException("Error! ForBid");
            }
            if (order.Status == false)
            {
                throw new AppException("Error! Completed order to rating");
            }
            if (order.Rate > 0)
            {
                throw new AppException("You have already rated. The rating cannot be edited");
            }

            order.Rate = orderParams.Rate;
            if (!string.IsNullOrWhiteSpace(orderParams.RateContent))
            {
                order.RateContent = orderParams.RateContent;
            }

            _context.Update(order);
            _context.SaveChanges();
        }
Пример #11
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,dropOffLat,pdropOffLat,pickUpLat,pickUpLon")] TaxiTrip taxiTrip)
        {
            if (id != taxiTrip.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(taxiTrip);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaxiTripExists(taxiTrip.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(taxiTrip));
        }
Пример #12
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SiteName,LogoPath,VanPercent,TaxiPercent")] GeneralSetting generalSetting)
        {
            if (id != generalSetting.Id)
            {
                return(NotFound());
            }
            if (generalSetting.TaxiPercent <= 0)
            {
                ModelState.AddModelError("TaxiPercent", "مقدار صفر برای قیمت پایه تاکسی سواری مجاز نیست");
            }
            if (generalSetting.VanPercent <= 0)
            {
                ModelState.AddModelError("VanPercent", "مقدار صفر برای قیمت پایه تاکسی ون مجاز نیست");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(generalSetting);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    throw ex;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(generalSetting));
        }
Пример #13
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,LastName,Age,Gender,Password,PhoneNubmber,IsMobielVerifed,Email,IsEmailVerified,AvatarPath,BirthDay,AllowActivity")] StudentParent studentParent)
        {
            if (id != studentParent.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(studentParent);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentParentExists(studentParent.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(studentParent));
        }
Пример #14
0
        public async Task <IActionResult> Edit(int id, [Bind("CarNumber,CarClass,CarSize")] Car car)
        {
            if (id != car.CarID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.CarID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(car));
        }
Пример #15
0
        public void SUpdate(Schedule scheduleParams)
        {
            var schedule = _context.Schedules.SingleOrDefault(x => x.DriverId == scheduleParams.DriverId);

            if (schedule == null)
            {
                throw new AppException("Schedule Not Found");
            }
            //update schedule info if provided
            if (scheduleParams.StartTime >= DateTime.Now)
            {
                schedule.StartTime = scheduleParams.StartTime;
            }
            else
            {
                throw new AppException("StartTime error");
            }

            if (!ProvinceList.Province.ContainsKey(scheduleParams.StartProvince) ||
                !ProvinceList.Province.ContainsKey(scheduleParams.DestinationProvince))
            {
                throw new AppException("Start or Destination province not provided service");
            }
            int start    = (int)ProvinceList.Province[scheduleParams.StartProvince];
            int end      = (int)ProvinceList.Province[scheduleParams.DestinationProvince];
            int distance = Math.Abs(start - end) + 1;

            if (distance > 4)
            {
                throw new AppException("It is not possible to choose a route longer than 4 provinces");
            }

            if (schedule.AvailablableSlot > _context.Vehicles.SingleOrDefault(e => e.DriverId == schedule.DriverId).Seater)
            {
                throw new AppException("AvailablableSlot > Vehicle's Seater");
            }
            if (scheduleParams.AvailablableSlot != 0)
            {
                schedule.AvailablableSlot = scheduleParams.AvailablableSlot;
            }

            schedule.StartProvince       = scheduleParams.StartProvince;
            schedule.DestinationProvince = scheduleParams.DestinationProvince;
            if (!string.IsNullOrWhiteSpace(scheduleParams.StartAddress))
            {
                schedule.StartAddress = scheduleParams.StartAddress;
            }
            if (!string.IsNullOrWhiteSpace(scheduleParams.DestinationAddress))
            {
                schedule.DestinationAddress = scheduleParams.DestinationAddress;
            }
            schedule.Updated = DateTime.Now;

            _context.Update(schedule);
            _context.SaveChanges();
        }
Пример #16
0
        //تغییر وضعیت درخواست
        public async Task <IActionResult> ChangeState(string id, RequsetSate RequsetState)
        {
            var serviceRequset = await _context.ServiceRequsets
                                 .FirstOrDefaultAsync(m => m.Id == id && m.AcademyId == User.GetAcademy().Id);

            if (serviceRequset == null)
            {
                return(NotFound());
            }
            try
            {
                serviceRequset.RequsetState = RequsetState;
                _context.Update(serviceRequset);
                await _context.SaveChangesWithHistoryAsync(HttpContext);

                ViewBag.msg = "تغییر وضعیت با موفقیت انجام شد";
                return(View(serviceRequset));
            }
            catch (DbUpdateException ex)
            {
                throw ex;
            }
        }
Пример #17
0
        public async Task <IActionResult> Edit(int id, [Bind("CarName,CarType,CarColor,IranianIdCode,DrivingLicense,DriverCode,PelakNumber,IsMaried,Id,Name,PhoneNubmber,Password,BeginDate,AllowActivity,AvatarPath")] Driver driver, IFormFile Avatar)
        {
            if (Avatar != null && Avatar.Length > (500 * 1024))
            {
                ModelState.AddModelError(nameof(Avatar), "حجم تصویر نباید بیش از 500 کیلو بایت باشد");
            }
            if (id != driver.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (Avatar != null)
                {
                    List <string> AllowedExtention = new List <string>()
                    {
                        ".jpg",
                        ".png"
                    };
                    var data = await AlphaRest.File.SendFileAsync(Avatar, AllowedExtention, (500 * 1024), $"{Const.DriverUploadFileApi}");

                    if (!string.IsNullOrWhiteSpace(data) && data != "false")
                    {
                        driver.AvatarPath = data;
                    }
                    else
                    {
                        ModelState.AddModelError(nameof(Avatar), "تصویر آپلود نشد");
                        return(View(driver));
                    }
                }
                try
                {
                    driver.ContractorId = User.GetContractor().Id;

                    _context.Update(driver);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    throw ex;
                }
                return(RedirectToAction(nameof(Details), new { id = driver.Id }));
            }
            return(View(driver));
        }
Пример #18
0
        public async Task <IActionResult> Edit(int id, [Bind("CarName,CarType,CarColor,IranianIdCode,DrivingLicense,DriverCode,PelakNumber,CityId,IsMaried,HasPlan,Id,Name,LastName,Age,Gender,Password,PhoneNubmber,IsMobielVerifed,Email,IsEmailVerified,BirthDay,BeginDate,AllowActivity,ContractorId")] Driver driver, IFormFile AvatarPath)
        {
            if (AvatarPath != null && AvatarPath.Length > (500 * 1024))
            {
                ModelState.AddModelError(nameof(AvatarPath), "حجم تصویر نباید بیش از 500 کیلو بایت باشد");
            }
            if (id != driver.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (AvatarPath != null)
                {
                    List <string> AllowedExtention = new List <string>()
                    {
                        ".jpg",
                        ".png"
                    };
                    var data = await AlphaRest.File.SendFileAsync(AvatarPath, AllowedExtention, (500 * 1024), $"{Const.StudentparrentPath}/api/api/Getdriverpic");

                    if (!string.IsNullOrWhiteSpace(data) && data != "false")
                    {
                        driver.AvatarPath = data;
                    }
                }
                try
                {
                    _context.Update(driver);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DriverExists(driver.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(driver));
        }
Пример #19
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,DriverId,TaxiSerivcestate,DriverPercent")] TaxiService taxiCab)
        {
            if (id != taxiCab.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(taxiCab);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);

                    if (taxiCab.TaxiCabState == TaxiCabState.Ready)
                    {
                        var txn = await _context.TaxiServices
                                  .Include(c => c.Passnegers)
                                  .ThenInclude(p => p.StudentParent)
                                  .FirstOrDefaultAsync(c => c.Id == taxiCab.Id);

                        if (txn != null)
                        {
                            foreach (var item in txn.Passnegers)
                            {
                                await _sms.SendNotifyWithTemplateAsync(item.StudentParent.PhoneNubmber, "https://20ro.net/Home/ActiveSerive", MessageTemplate.Bisrobreif);
                            }
                        }
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    //if (!TaxiCabExists(taxiCab.Id))
                    //{
                    //    return NotFound();
                    //}
                    //else
                    //{
                    //    throw;
                    //}
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DriverId"] = new SelectList(_context.Drivers.Undelited(), "Id", "Name", taxiCab.DriverId);
            return(View(taxiCab));
        }
Пример #20
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,StudentParrentId,FullName,Age,Address,Note,CourseId,RequsetState")] ServiceRequset serviceRequset)
        {
            if (id != serviceRequset.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(serviceRequset);
                    await _context.SaveChangesWithHistoryAsync(HttpContext);
                }
                catch (DbUpdateConcurrencyException)
                {
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StudentParrentId"] = new SelectList(_context.StudentParents, "Id", "Name", serviceRequset.StudentParrentId);
            return(View(serviceRequset));
        }