public ActionResult Create([Bind(Include = "ID,Name,Address,Email,Phone,SelectedItems")] SupplierDto supplier) { if (ModelState.IsValid) { if (supplier.SelectedItems != null && supplier.SelectedItems.Length > 0) { supplier.Groups = new List <GroupDto>(); /* Split SelectedGroups by ';' */ string[] groupStrs = supplier.SelectedItems.Split(';'); /* Iterate through groupStrs, add selected groups into supplierDb and remeber tested groups */ foreach (string groupStr in groupStrs) { try { int id = Int32.Parse(groupStr.Replace("Group_", "")); supplier.Groups.Add(GroupService.GetById(id)); } catch (FormatException) { ; } } } SupplierService.Add(supplier); return(RedirectToAction("Index")); } return(View(supplier)); }
public HttpResponseMessage Create(HttpRequestMessage request, SupplierViewModel model) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var newSupplierModel = new Supplier(); var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; newSupplierModel.UpdateSupplier(model); newSupplierModel.Created = DateTime.Now; _SupplierService.Add(newSupplierModel); _SupplierService.Save(); Log log = new Log() { AppUserId = claims.FirstOrDefault().Value, Content = Notification.CREATE_SUPPLIER, Created = DateTime.Now }; _logService.Create(log); _logService.Save(); var responseData = Mapper.Map <Supplier, SupplierViewModel>(newSupplierModel); response = request.CreateResponse(HttpStatusCode.OK, responseData); } return response; })); }
public async Task <IActionResult> SaveEntity(SupplierViewModel supplierViewModel) { if (!ModelState.IsValid) { var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (supplierViewModel.Id == 0) { var notificationId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel { Title = User.GetSpecificClaim("FullName"), DateCreated = DateTime.Now, Content = $"Supplier {supplierViewModel.FullName} has been created", Id = notificationId, UserId = User.GetUserId(), Image = User.GetSpecificClaim("Avatar"), Status = Status.Active }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; _supplierService.Add(announcement, announcementUsers, supplierViewModel); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } else { var notificationId = Guid.NewGuid().ToString(); var announcement = new AnnouncementViewModel { Title = User.GetSpecificClaim("FullName"), DateCreated = DateTime.Now, Content = $"Supplier {supplierViewModel.FullName} has been updated", Id = notificationId, UserId = User.GetUserId(), Image = User.GetSpecificClaim("Avatar"), Status = Status.Active }; var announcementUsers = new List <AnnouncementUserViewModel>() { new AnnouncementUserViewModel() { AnnouncementId = notificationId, HasRead = false, UserId = User.GetUserId() } }; _supplierService.Update(announcement, announcementUsers, supplierViewModel); await _hubContext.Clients.All.SendAsync("ReceiveMessage", announcement); } _supplierService.Save(); return(new OkObjectResult(supplierViewModel)); } }
public IActionResult Add([FromBody] AddSupplier supplier) { var mappedSupplier = _mapper.Map <Supplier>(supplier); var response = _service.Add(mappedSupplier); return(Ok(response)); }
public IActionResult Create([Bind("SupplierID,Name,Street,Number,Zip code,City,State,Country,ServiceDeskTel,ServiceDeskMail,ServiceDeskWeb,IsActief,HasHardware,HasSoftware")] Supplier supplier) { if (ModelState.IsValid) { service.Add(supplier); return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public IActionResult Add(SupplierForAddDto supplierForAddDto) { var result = supplierService.Add(supplierForAddDto); if (result.Success) { return(CreatedAtAction("GetById", new { id = result.Data }, result.Message)); } return(BadRequest(result.Message)); }
public IActionResult Add(Supplier supplier) { var result = _supplierService.Add(supplier); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public async Task <ActionResult <SupplierViewModel> > Add(SupplierViewModel supplierViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _supplierService.Add(_mapper.Map <Supplier>(supplierViewModel)); return(CustomResponse(supplierViewModel)); }
public IActionResult Post([FromBody] Supplier model) { if (!ModelState.IsValid) { return(BadRequest()); } var createdSupplier = _supplierService.Add(model); return(Ok(createdSupplier)); }
public ActionResult Create(Supplier supplier) { if (!ModelState.IsValid) { ErrorNotification("Kayıt Eklenemedi!"); return(View("Create")); } _supplierService.Add(supplier); SuccessNotification("Kayıt Eklendi."); return(RedirectToAction("Index")); }
public HttpResponseMessage Post(Supplier Supplier) { try { return(Request.CreateResponse(HttpStatusCode.OK, supplierService.Add(Supplier))); } catch (Exception e) { Console.Write(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, e)); } }
public JavaScriptResult Create(SupplierViewModel vm) { try { _supplierService.Add(Mapper.Map <Supplier>(vm)); return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/Supplier/"}')")); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }
public ActionResult Create(Supplier supplier) { try { supplierService.Add(supplier); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <ActionResult> Post([FromBody] Supplier value) { try { var result = await supplierService.Add(value); return(Ok(result)); } catch (Exception) { return(BadRequest()); } }
public ActionResult Create(SupplierEditModel model) { if (!ModelState.IsValid) { return(View(model)); } model.Supplier.Updated = DateTime.Now; model.Supplier.ByUser = User.Identity.Name; _service.Add(model.Supplier); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([FromBody] Supplier model) { model.CreatedAt = DateTime.Now; if (ModelState.IsValid) { if (await _supplierService.Add(model)) { return(new CreatedAtRouteResult(nameof(GetById), new { id = model.Id }, model)); } return(BadRequest("Lo sentimos, no se ha podido crear el suplidor")); } return(BadRequest("Algunos valores estan incorrectos")); }
public async Task <IActionResult> Create(SuppilerDto create) { if (_supplierService.GetById(create.ID) != null) { return(BadRequest("Line ID already exists!")); } //create.CreatedDate = DateTime.Now; if (await _supplierService.Add(create)) { return(NoContent()); } throw new Exception("Creating the model name failed on save"); }
public ActionResult Add([FromBody] Supplier supplier) { var result = _supplierService.Validate(supplier); if (!result.IsValid) { _logger.Info($"Failed to add Supplier: {supplier.Name} due to validation issues"); return(BadRequest(result.Messages)); } var id = _supplierService.Add(supplier); return(Created(Url.Action("Get", id), supplier)); }
public IHttpActionResult PostProduct([FromBody] SupplierDTO supplier) { if (supplier == null) { return(BadRequest($"{supplier} is null")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _supplierService.Add(supplier); return(Ok()); }
public async Task <ActionResult <SupplierModel> > AddSupplier(SupplierModel supplierModel) { var supplier = _mapper.Map <Supplier>(supplierModel); _supplierService.Add(supplier); if (await _supplierService.IsSavedToDb()) { var persistedSupplierModel = _mapper.Map <SupplierModel>(supplier); return(CreatedAtAction(nameof(GetSupplier), new { supplierId = persistedSupplierModel.SupplierId }, persistedSupplierModel)); } return(BadRequest()); }
public ActionResult Create(Supplier supplier) { try { supplier.CreatedBy = User.Identity.Name; supplier.CreatedDate = DateTime.Now; supplierService.Add(supplier); supplierService.Save(); return(RedirectToAction("Index")); } catch (Exception) { return(View(supplier)); } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create(SupplierViewModel supplierViewModel) { if (!ModelState.IsValid) { return(View(supplierViewModel)); } var supplier = _mapper.Map <Supplier>(supplierViewModel); await _service.Add(supplier); if (!ValidOperation()) { return(View(supplierViewModel)); } return(RedirectToAction("Index")); }
public ActionResult Create(Supplier supplier, HttpPostedFileBase image) { if (image != null) { WebImage img = new WebImage(image.InputStream); FileInfo fotoInfo = new FileInfo(image.FileName); string newFoto = Guid.NewGuid().ToString() + fotoInfo.Extension; img.Resize(800, 350); img.Save("~/Uploads/Supplier/" + newFoto); supplier.Logo = "/Uploads/Supplier/" + newFoto; } _supplierService.Add(supplier); return(RedirectToAction("Index")); }
private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtName.Text)) { epName.SetError(txtName, "Name error"); } else { string name = txtName.Text; Supplier supplier = new Supplier() { CompanyName = name, }; supplierService.Add(supplier); this.Close(); } }
private void btnThem_Click(object sender, EventArgs e) { btnThem.Text = btnThem.Text.Equals("Thêm nhà cung cấp") ? "Lưu" : "Thêm nhà cung cấp"; if (btnThem.Text.Equals("Thêm nhà cung cấp")) // An nut them lan 2 { if (!isValid()) { MessageBox.Show("Bạn phải nhập đầy đủ thông tin !!!"); btnThem.Text = "Lưu"; return; } //Code GenericResult rs = _supplierService.Add(new SupplierViewModel() { FullName = txtTen.Text.Trim(), Address = txtDiaChi.Text.Trim(), DateCreated = DateTime.Now, PhoneNumber = txtSoDT.Text.Trim(), Status = chkTrangThai.Checked == true ? Status.Active : Status.InActive }); _supplierService.Save(); if (rs.Success) { FormHelper.showSuccessDialog(rs.Message, rs.Caption); } else { FormHelper.showErrorDialog(rs.Message, rs.Error, rs.Caption); } //End Code loadGvNhaCungCap(); update_Edit(); gv_NhaCC.Enabled = true; setBtnBack_False(); setEdit_False(); } else //Vua nhan nut them { setEdit_True(); saveStament(); setBtnBack_True(); reStart(); gv_NhaCC.Enabled = false; } }
public async Task <ActionResult <bool> > Post(SupplierVM supplierVM) { if (supplierVM == null) { ModelState.AddModelError("paramEmpty", "Request cannot be empty"); return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await supplierService.Add(supplierVM); if (result == false) { return(StatusCode(500, "Request could not be processed")); } return(Created($"api/supplier/{supplierVM.ID}", result)); }
private void CreateBtn_Click(object sender, EventArgs e) { try { Supplier supplier = new Supplier { CompanyName = CreateCompanyNameTxt.Text, EMail = CreateEMailTxt.Text, PhoneNumber = CreatePhoneNumberTxt.Text, }; createMessage.CreateMessageBox(supplierService.Add(supplier)); SupplierGridViewGetAll(); CreateCompanyNameTxt.Text = ""; CreateEMailTxt.Text = ""; CreatePhoneNumberTxt.Text = ""; } catch (Exception) { MessageBox.Show("Tekrar deneyiniz..."); } }
public IActionResult SaveSupplier(DTOSupplier model) { if (model.Id == 0) { _supplierService.Add(model); var n = new Notification { DateTime = DateTime.Now, Text = $"New supplier - {model.Name}", UserId = int.Parse(_userManager.GetUserId(HttpContext.User)) }; _notification.Create(n); } else { _supplierService.Edit(model); } return(RedirectToAction(nameof(Index))); }
private void BtnCompanyAdd_Click(object sender, EventArgs e) { if (_suppliersList.Exists(a => a.SupplierId == _supplierId)) // Kullanici DataGrid ten kayit secip onu tekrardan eklemek isterse burada kontrol saglayip eger o kayit varsa ekletmiyoruz. { MessageBox.Show("Ayni Kayidi Eklemeye Calisiyorsunuz."); } else // Yeni Kayit Ekleme { _supplierService.Add(new Supplier { Address = TxtCompanyAddress.Text, City = TxtCompanyCity.Text, CompanyName = TxtCompanyName.Text, ContactName = TxtContactName.Text, District = TxtCompanyDistrict.Text, Phone = TxtCompanyPhone.Text, PostalCode = TxtCompanyPostalCode.Text }); MessageBox.Show("KAYIT BASARILI BIR SEKILDE EKLENDI..."); CleanTheTextBox(); DataGridSupplierOperations.DataSource = _supplierService.GetSuppliers(); } }
public ActionResult Add(SupplierDto model, string supplierModes) { model.SupplierModeIds = supplierModes.Split(',').Select(int.Parse).ToArray(); _supplierService.Add(model); return(Json(new { code = 200, message = "操作完成!", url = "/supplier" })); }