public AddStorePage() { InitializeComponent(); ViewModel = new AddStoreViewModel(); BindingContext = ViewModel; foreach (string category in AppConstants.CATEGORIES) { categoryPicker.Items.Add(category); } var tagEntryView = new TagEntryView() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, TagValidatorFactory = new Func <string, object>((arg) => ViewModel.ValidateAndReturn(arg)), TagViewFactory = new Func <View>(() => new TagItemView()) }; tagEntryView.SetBinding <AddStoreViewModel>(TagEntryView.TagItemsProperty, v => v.Items); tagEntryView.TagTapped += (sender, e) => { if (e.Item != null) { ViewModel.RemoveTag((TagItem)e.Item); } }; tagEntryWrapper.Children.Add(tagEntryView); }
public IActionResult Add(AddStoreViewModel addStoreViewModel) { if (ModelState.IsValid) { ItemStore newStore = new ItemStore { Name = addStoreViewModel.Name, }; context.Stores.Add(newStore); context.SaveChanges(); return(Redirect("/Store")); } return(View(addStoreViewModel)); }
public ActionResult AddStore(AddStoreViewModel model) { if (!this.ModelState.IsValid) { return this.View(model); } var userId = this.User.Identity.GetUserId(); var store = new Store(); store.UserId = userId; store.Name = model.Name; store.Username = model.Username; store.Password = model.Password; store.Url = model.Url; this.stores.Add(store); this.stores.SaveChanges(); return this.View(); }
public async Task <IActionResult> Post([FromBody] AddStoreViewModel model) { if (model == null) { return(BadRequest()); } Guid?accountId = null; if (model.AccountId.HasValue) { var account = await _accountRepo.GetAsync(model.AccountId.Value); if (account == null) { return(NotFound(Resources.Accounts.AccountResource.AccountNotFound)); } accountId = account.Id; } Guid?costCenterId = null; if (model.CostCenterId.HasValue) { var costCenter = await _costCenterRepo.GetAsync(model.CostCenterId.Value); if (costCenter == null) { return(NotFound(Resources.CostCenters.CostCenterResource.CostCenterNotFound)); } costCenterId = costCenter.Id; } Guid?parentId = null; if (model.ParentId.HasValue) { var parentStore = await _storeRepo.GetAsync(model.ParentId.Value); if (parentStore == null) { return(NotFound(Resources.Stores.StoreResource.ParentStoreNotFound)); } parentId = parentStore.Id; } if (await _storeRepo.IsExistCodeAsync(model.Code)) { ModelState.AddModelError("Code", Resources.Global.Common.ThisCodeExist); } if (await _storeRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); } if (!ModelState.IsValid) { return(BadRequest(ModelState.GetWithErrorsKey())); } var store = new Store(model.Name, model.Code, accountId, costCenterId, model.Note); if (parentId.HasValue) { store.ParentId = parentId.Value; } var affectedRows = await _storeRepo.AddAsync(store); if (affectedRows > 0) { _storeRepo.LoadReferences(store); var viewModel = AutoMapper.Mapper.Map <StoreViewModel>(store); return(CreatedAtRoute("GetStore", new { id = store.Number }, viewModel)); } return(BadRequest()); }
public IActionResult Add() { AddStoreViewModel addStoreViewModel = new AddStoreViewModel(); return(View(addStoreViewModel)); }
public AddStorePage(int userId) { InitializeComponent(); BindingContext = _viewModel = new AddStoreViewModel(userId, map); }
public async Task <ActionResult> Index(AddStoreViewModel model) { model.Store.Description = model.Store.Description ?? ""; if (!ModelState.IsValid) { return(View(model)); } MultipartFormDataContent content; bool FileAttached = (Request.RequestContext.HttpContext.Session["AddStoreImage"] != null); bool ImageDeletedOnEdit = false; var imgDeleteSessionValue = Request.RequestContext.HttpContext.Session["ImageDeletedOnEdit"]; if (imgDeleteSessionValue != null) { ImageDeletedOnEdit = Convert.ToBoolean(imgDeleteSessionValue); } byte[] fileData = null; var ImageFile = (HttpPostedFileWrapper)Request.RequestContext.HttpContext.Session["AddStoreImage"]; if (FileAttached) { using (var binaryReader = new BinaryReader(ImageFile.InputStream)) { fileData = binaryReader.ReadBytes(ImageFile.ContentLength); } } ByteArrayContent fileContent; JObject response; bool firstCall = true; callAgain : content = new MultipartFormDataContent(); if (FileAttached) { fileContent = new ByteArrayContent(fileData); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = ImageFile.FileName }; content.Add(fileContent); } if (model.Store.Id > 0) { content.Add(new StringContent(model.Store.Id.ToString()), "Id"); } content.Add(new StringContent(model.Store.Name), "StoreName"); content.Add(new StringContent(model.Store.Latitude.ToString()), "Lat"); content.Add(new StringContent(model.Store.Longitude.ToString()), "Long"); content.Add(new StringContent(model.Store.Open_From.ToString()), "Open_From"); content.Add(new StringContent(model.Store.Open_To.ToString()), "Open_To"); content.Add(new StringContent(Convert.ToString(model.Store.Description)), "Description"); content.Add(new StringContent(Convert.ToString(model.Store.Address)), "Address"); content.Add(new StringContent(Convert.ToString(ImageDeletedOnEdit)), "ImageDeletedOnEdit"); var packageProducts = JsonConvert.SerializeObject(model.Store.StoreDeliveryHours); var buffer = System.Text.Encoding.UTF8.GetBytes(packageProducts); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); content.Add(byteContent, "StoreDeliveryHours"); response = await ApiCall.CallApi("api/Admin/AddStore", User, isMultipart : true, multipartContent : content); if (firstCall && Convert.ToString(response).Contains("UnAuthorized")) { firstCall = false; goto callAgain; } else if (Convert.ToString(response).Contains("UnAuthorized")) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "UnAuthorized Error")); } if (response is Error) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, (response as Error).ErrorMessage)); } else { model.SetSharedData(User); if (model.Role == RoleTypes.SuperAdmin) { if (model.Store.Id > 0) { TempData["SuccessMessage"] = "The store has been updated successfully."; } else { TempData["SuccessMessage"] = "The store has been added successfully."; } } return(Json(new { success = true, responseText = "Success" }, JsonRequestBehavior.AllowGet)); } }
public AddStore(Good good) { InitializeComponent(); BindingContext = new AddStoreViewModel(good, this); }