public IActionResult Upsert(GarageViewModel garagevm) { try { if (ModelState.IsValid) { if (garagevm.Garage.Id == 0) { _unitOfWork.Garage.Add(garagevm.Garage); } else { _unitOfWork.Garage.Update(garagevm.Garage); } _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } }catch (Exception ex) { var evm = new ErrorViewModel(); evm.ErrorMessage = ex.Message.ToString(); return(View("Error", evm)); } return(View(garagevm)); }
public IActionResult Add(GarageViewModel model) { var garageEntityForCreation = _mapper.Map <Garage>(model); _garageService.InsertGarage(garageEntityForCreation); return(RedirectToAction("Index")); }
//Insert or Update action for Garage public IActionResult Upsert(int?id) { GarageViewModel garagevm = new GarageViewModel() { Garage = new Garage(), ClosestGarageList = _unitOfWork.Garage.GetAll(u => u.Id != id.GetValueOrDefault()).Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; try { if (id == null) { return(View(garagevm)); } garagevm.Garage = _unitOfWork.Garage.Get(id.GetValueOrDefault()); if (garagevm.Garage == null) { throw new Exception("Unable to find the garage"); } } catch (Exception ex) { var evm = new ErrorViewModel(); evm.ErrorMessage = ex.Message.ToString(); return(View("Error", evm)); } return(View(garagevm)); }
public async Task <IActionResult> Create() { try { var branding = await _referenceService.GetBranding(1); var model = new GarageViewModel() { BrandingId = 1, HelpLinkFr = branding.HelpLinkFr, HelpLinkEn = branding.HelpLinkEn, StoreLinkFr = branding.StoreLinkFr, StoreLinkEn = branding.StoreLinkEn, BrandingLogo = $"{branding.LogoUrl}/1_logo.jpg", ActivationDate = DateTime.Now.ToString("yyyy-MM-dd"), BannerList = await _referenceService.GetBannerSelectListItem(), LanguageList = await _referenceService.GetLanguageSelectList(CurrentUser.GarageSetting.Language), DateFormatList = _referenceService.GetDateFormatSelectList(), RootUrl = BaseRootUrl }; return(View(model)); } catch (Exception ex) { ex.ToExceptionless().Submit(); return(BadRequest()); } }
public IActionResult Edit(GarageViewModel model) { var garageForEdit = _mapper.Map <Garage>(model); _garageService.EditGarage(garageForEdit); return(RedirectToAction("Index")); }
// GET: Garages/Create public ActionResult Create() { GarageViewModel model = new GarageViewModel(); ViewBag.StateId = new SelectList(db.States, "Id", "StateName"); ViewBag.CityId = new SelectList(db.Cities, "Id", "CityName"); model.AvailableServiceDays = ListHelper.GetDayNameList(); return(View(model)); }
protected override void Dispose(bool disposing) { if (disposing) { Console.WriteLine($"Disposing {GetType().Name}"); if (_garageViewModel != null) { _garageViewModel.Dispose(); _garageViewModel = null; } } base.Dispose(disposing); }
public async Task <IActionResult> Edit(GarageViewModel model) { try { var result = await _garageService.Update(model); return(Ok(result)); } catch (Exception ex) { ex.ToExceptionless().Submit(); return(BadRequest()); } }
public async Task <int> Update(GarageViewModel model) { try { model.Phone = model.Phone.ToPhoneDatabase(); var factoryModel = model.Adapt <GarageModel>(); return(await _garageFactory.Update(factoryModel)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> UpdateGarage() { ResponseDataDTO <int> response = new ResponseDataDTO <int>(); try { var path = Path.GetTempPath(); MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path); GarageViewModel GarageViewModel = new GarageViewModel { GarageID = Guid.Parse(streamProvider.FormData["GarageID"]), GarageName = Convert.ToString(streamProvider.FormData["GarageName"]), Address = Convert.ToString(streamProvider.FormData["Address"]), DateStart = Convert.ToDateTime(streamProvider.FormData["DateStart"]), DateEnd = Convert.ToDateTime(streamProvider.FormData["DateEnd"]) }; var existGarage = _Garageservice.Find(GarageViewModel.GarageID); // mapping view model to entity var updatedGarage = _mapper.Map <Garage>(GarageViewModel); // update quantity updatedGarage.GarageName = existGarage.GarageName; updatedGarage.Address = existGarage.Address; updatedGarage.DateStart = existGarage.DateStart; updatedGarage.DateEnd = existGarage.DateEnd; // update Garage _Garageservice.Update(updatedGarage, updatedGarage.GarageID); // return response response.Code = HttpCode.OK; response.Message = MessageResponse.SUCCESS; response.Data = 1; return(Ok(response)); } catch (Exception ex) { response.Code = HttpCode.INTERNAL_SERVER_ERROR; response.Message = MessageResponse.FAIL; response.Data = 0; Console.WriteLine(ex.ToString()); return(Ok(response)); } }
public async Task <int> Create(GarageViewModel model) { try { //default to Canada model.Country = "CA"; model.Phone = model.Phone.ToPhoneDatabase(); var factoryModel = model.Adapt <GarageModel>(); var garageId = await _garageFactory.Create(factoryModel); //Copy Sticker Logo await _blobStorageService.CopyBlob(garageId, "logos"); return(garageId); } catch (Exception ex) { throw ex; } }
public async Task <ActionResult> Index() { ViewBag.Title = "Manage Garage"; try { string userId = this.User.Identity.GetUserId(); ApplicationUser user = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(userId); if (user?.Tracks.Count == 0) { return(RedirectToAction("Index", "RegisterTrack")); } else { GarageViewModel garageModel = new GarageViewModel(); var trackId = TempData["TrackId"]; if (trackId != null) { garageModel.SelectedTrackId = trackId.ToString(); } var carId = TempData["CarId"]; if (carId != null) { garageModel.SelectedCarId = carId.ToString(); } await garageModel.Setup(user); return(View(garageModel)); } } catch (Exception) { return(RedirectToAction("Index", "Home")); } }
// GET: Garages/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Garage entity = db.Garages.Find(id); if (entity == null) { return(HttpNotFound()); } ViewBag.StateId = new SelectList(db.States, "Id", "StateName", entity.State); ViewBag.CityId = new SelectList(db.Cities.Where(b => b.StateID == entity.State), "Id", "CityName", entity.City); GarageViewModel model = new GarageViewModel(); model.GarageId = entity.GarageId; model.Garage_Name = entity.Garage_Name; model.Contact_Person = entity.Contact_Person; model.Email = entity.Email; model.Phone_Number = entity.Phone_Number; model.IsActive = entity.IsActive; model.Garage_Address = entity.Garage_Address; model.City = entity.City; model.State = entity.State; model.Pincode = entity.Pincode; model.OpenTime = entity.OpenTime; model.CloseTime = entity.CloseTime; model.ServiceDays = entity.ServiceDays.Split(','); model.AvailableServiceDays = ListHelper.GetDayNameList(); model.AvailableSubscriptionTypes = ListHelper.GetSubscriptionTypeList(); return(View(model)); }
public ActionResult Create(GarageViewModel model) { model.Country = "US"; model.CreatedDt = DateTime.Now.Date; model.CreatedBy = "ADmin"; IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "AIzaSyDfIuSL-y1mkKLD5pKFiMb6sT7ZP6MLTjs" }; IEnumerable <Address> addresses = geocoder.Geocode(model.Garage_Address); model.Latitute = addresses.First().Coordinates.Latitude; model.Longitude = addresses.First().Coordinates.Longitude; ModelState.Remove("State"); ModelState.Remove("City"); ModelState.Remove("Country"); if (ModelState.IsValid) { Garage entity = new Garage(); entity.Garage_Name = model.Garage_Name; entity.Contact_Person = model.Contact_Person; entity.Garage_Address = model.Garage_Address; entity.Phone_Number = model.Phone_Number; entity.Email = model.Email; entity.IsActive = model.IsActive.HasValue ? model.IsActive.Value : false; entity.Garage_Address = model.Garage_Address; entity.City = model.City; entity.State = model.State; entity.Pincode = model.Pincode; entity.OpenTime = model.OpenTime; entity.CloseTime = model.CloseTime; //entity.ServiceDays = model.ServiceDays; entity.ServiceDays = string.Join(",", model.ServiceDays); entity.Country = "US"; entity.CreatedDt = DateTime.Now.Date; entity.CreatedBy = "Admin"; entity.Latitute = model.Latitute; entity.Longitude = model.Longitude; try { db.Garages.Add(entity); db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } AddNotification(Models.NotifyType.Success, "Records Successfully Saved.", true); return(RedirectToAction("Index")); } ViewBag.StateId = new SelectList(db.States, "Id", "StateName", model.State); ViewBag.CityId = new SelectList(db.Cities.Where(b => b.StateID == model.State), "Id", "CityName", model.City); model.AvailableServiceDays = ListHelper.GetDayNameList(); model.AvailableSubscriptionTypes = ListHelper.GetSubscriptionTypeList(); return(View(model)); }
public override void ViewDidLoad() { base.ViewDidLoad(); var maxWidth = UIScreen.MainScreen.Bounds.Width - (MARGIN + SPACING + MARGIN); var buttonHeight = maxWidth * 2; _garageViewModel = new GarageViewModel(); _buttonStack = new UIStackView(); _leftButton = new UIButton(UIButtonType.Custom); _rightButton = new UIButton(UIButtonType.Custom); _retryButton = new UIButton(UIButtonType.Custom); _leftStatus = new UILabel(); _rightStatus = new UILabel(); _connectionStatus = new UILabel(); _leftButton.HeightAnchor.ConstraintEqualTo(buttonHeight).Active = true; _leftButton.WidthAnchor.ConstraintEqualTo(maxWidth / 2).Active = true; _rightButton.HeightAnchor.ConstraintEqualTo(buttonHeight).Active = true; _rightButton.WidthAnchor.ConstraintEqualTo(maxWidth / 2).Active = true; _connectionStatus.WidthAnchor.ConstraintEqualTo(maxWidth).Active = true; _buttonStack.ContentMode = UIViewContentMode.ScaleAspectFill; _buttonStack.Alignment = UIStackViewAlignment.Fill; _buttonStack.Distribution = UIStackViewDistribution.FillEqually; _buttonStack.Axis = UILayoutConstraintAxis.Horizontal; _buttonStack.TranslatesAutoresizingMaskIntoConstraints = false; _buttonStack.Spacing = MARGIN / 2; _buttonStack.AddArrangedSubview(_leftButton); _buttonStack.AddArrangedSubview(_rightButton); View.BackgroundColor = UIColor.White; _leftLetter = new UILabel { Text = "L", TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(150, UIFontWeight.Semibold), TranslatesAutoresizingMaskIntoConstraints = false }; _leftLetter.Layer.Opacity = 0.4f; _leftStatus = new UILabel { Text = "Unknown", TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(16.0f, UIFontWeight.Regular), TranslatesAutoresizingMaskIntoConstraints = false }; _leftButton.BackgroundColor = UIColor.FromRGB(65, 217, 73); _rightLetter = new UILabel { Text = "R", TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(150, UIFontWeight.Semibold), TranslatesAutoresizingMaskIntoConstraints = false }; _rightLetter.Layer.Opacity = 0.4f; _rightStatus = new UILabel { Text = "Unknown", TextAlignment = UITextAlignment.Center, TextColor = UIColor.White, Font = UIFont.SystemFontOfSize(16.0f, UIFontWeight.Regular), TranslatesAutoresizingMaskIntoConstraints = false }; _rightButton.BackgroundColor = UIColor.FromRGB(247, 210, 0); _connectionStatus.Layer.Opacity = 0; _buttonStack.Layer.Opacity = 0; _connectionStatus.Text = _garageViewModel.Status; _connectionStatus.TextAlignment = UITextAlignment.Center; _connectionStatus.Font = UIFont.BoldSystemFontOfSize(16.0f); _leftButton.AddSubviews(_leftLetter, _leftStatus); _rightButton.AddSubviews(_rightLetter, _rightStatus); View.AddSubviews(_buttonStack, _connectionStatus); View.ConstrainLayout(() => _buttonStack.Frame.GetCenterY() == View.Frame.GetCenterY() && _buttonStack.Frame.Left == View.Frame.Left + MARGIN && _buttonStack.Frame.Right == View.Frame.Left - MARGIN && _buttonStack.Frame.Height == View.Frame.Height * 0.5f && _connectionStatus.Frame.Top == _buttonStack.Frame.Top * 0.5f && _connectionStatus.Frame.GetCenterX() == View.Frame.GetCenterX() && _connectionStatus.Frame.Height == 40 ); _leftButton.ConstrainLayout(() => _leftLetter.Frame.GetCenterY() == _leftButton.Frame.GetCenterY() && _leftLetter.Frame.GetCenterX() == _leftButton.Frame.GetCenterX() && _leftStatus.Frame.GetCenterX() == _leftButton.Frame.GetCenterX() && _leftStatus.Frame.Top == _leftLetter.Frame.Bottom - 20.0f ); _rightButton.ConstrainLayout(() => _rightLetter.Frame.GetCenterY() == _rightButton.Frame.GetCenterY() && _rightLetter.Frame.GetCenterX() == _rightButton.Frame.GetCenterX() && _rightStatus.Frame.GetCenterX() == _rightButton.Frame.GetCenterX() && _rightStatus.Frame.Top == _rightLetter.Frame.Bottom - 20.0f ); _didBecomeActiveObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, HandleDidBecomeActiveNotification); }
public ActionResult Edit(GarageViewModel model) { bool findLatLong = false; Garage entity = db.Garages.Find(model.GarageId); if (entity == null) { return(HttpNotFound()); } ModelState.Remove("State"); ModelState.Remove("City"); ModelState.Remove("Country"); ViewBag.StateId = new SelectList(db.States, "Id", "StateName", model.State); ViewBag.CityId = new SelectList(db.Cities.Where(b => b.StateID == model.State), "Id", "CityName", model.City); try { IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "AIzaSyA3CNMI-_JAV9-dWIctroZQTuUwjZygT3A" }; IEnumerable <Address> addresses = geocoder.Geocode(model.Garage_Address); model.Latitute = addresses.First().Coordinates.Latitude; model.Longitude = addresses.First().Coordinates.Longitude; findLatLong = true; } catch { findLatLong = false; } model.CreatedDt = DateTime.Now.Date; model.CreatedBy = User.Identity.Name; model.Country = "US"; if (ModelState.IsValid) { entity.Garage_Name = model.Garage_Name; entity.Contact_Person = model.Contact_Person; entity.Garage_Address = model.Garage_Address; entity.Phone_Number = model.Phone_Number; entity.Email = model.Email; entity.IsActive = model.IsActive.HasValue ? model.IsActive.Value : false; entity.Garage_Address = model.Garage_Address; entity.City = model.City; entity.State = model.State; entity.Pincode = model.Pincode; entity.OpenTime = model.OpenTime; entity.CloseTime = model.CloseTime; //entity.ServiceDays = model.ServiceDays; entity.ServiceDays = string.Join(",", model.ServiceDays); if (findLatLong) { entity.Latitute = model.Latitute; entity.Longitude = model.Longitude; } try { db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } AddNotification(Models.NotifyType.Success, "Records Successfully Updated.", true); return(RedirectToAction("Index")); } ViewBag.StateId = new SelectList(db.States, "Id", "StateName", model.State); ViewBag.CityId = new SelectList(db.Cities.Where(b => b.StateID == model.State), "Id", "CityName", model.City); model.AvailableServiceDays = ListHelper.GetDayNameList(); model.AvailableSubscriptionTypes = ListHelper.GetSubscriptionTypeList(); return(View(model)); }
public IActionResult Add() { var garageViewModelForCreation = new GarageViewModel(); return(View(garageViewModelForCreation)); }