public void Save() { if (CheckData()) { CityService service = new CityService(); if ((this.DataContext as CityEntity).Id == -1 && !CheckDoppione()) { if (service.Add(this.DataContext as CityEntity) == 0) { MessageBox.Show("Salvato!"); this.DataContext = new CityEntity(); } else { MessageBox.Show("Errore durante il salvataggio!"); } } else { if (service.Update(this.DataContext as CityEntity) == 0) { MessageBox.Show("Salvato!"); } else { MessageBox.Show("Errore durante il salvataggio!"); } } } }
public async Task <ResponceModel> Add([FromBody] City model) { var identifier = User.Claims.FirstOrDefault(p => p.Type == "id"); if (identifier == null) { return(new ResponceModel(401, "Unauthorized", null, new string[] { "Yetkilendirme Hatası." })); } try { var city = await cityService.Add(model); if (await cityService.SaveChangesAsync()) { return(new ResponceModel(200, "OK", city, null)); } else { return(new ResponceModel(400, "ERROR", null, new string[] { "Göneri gönderilirken bir sorun oluştu." })); } } catch (Exception ex) { await _logService.Add(new SystemLog() { Content = ex.Message, CreateDate = DateTime.Now, UserId = 0, EntityName = cityService.GetType().Name }); return(new ResponceModel(500, "ERROR", null, new string[] { "Gönderi eklenirken bir hata oluştu." })); } }
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { CityService.Delete(SQLDataHelper.GetInt(e.CommandArgument)); } if (e.CommandName == "AddCity") { var footer = grid.FooterRow; if (string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewName")).Text)) { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ffcccc"); return; } CityService.Add(new City { Name = ((TextBox)footer.FindControl("txtNewName")).Text, CitySort = ((TextBox)footer.FindControl("txtNewSort")).Text.TryParseInt(), RegionId = RegionId, DisplayInPopup = ((CheckBox)footer.FindControl("chkNewDisplayInPopup")).Checked, PhoneNumber = ((TextBox)footer.FindControl("txtNewPhoneNumber")).Text }); grid.ShowFooter = false; } if (e.CommandName == "CancelAdd") { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc"); grid.ShowFooter = false; } }
public ActionResult Create(CityViewModel modl) { if (ModelState.IsValid) { _CityService.Add(modl.objCity); return(RedirectToAction("Index")); } return(View("Create", modl)); }
public void Post(List <CityRequest> cityReqList) { using (CityService cityService = new CityService()) { foreach (var item in cityReqList) { //City cityModel = new City(); cityService.Add(new City() { CityId = item.Id, CityName = item.Name, Country = item.Country, CityLat = item.Coord.Lat, CityLon = item.Coord.Lon }); } } }
public void ReturnProper_AddCity_ResultFromCommitMethod() { // Arrange var citiesRepoMock = new Mock <IEfRepository <City> >(); var uowMock = new Mock <ISaveContext>(); citiesRepoMock.Setup(c => c.Add(It.IsAny <City>())).Verifiable(); uowMock.Setup(u => u.Commit()).Returns(1); var cityService = new CityService(citiesRepoMock.Object, uowMock.Object); // Act var result = cityService.Add(It.IsAny <City>()); // Assert Assert.That(result.Equals(1)); }
public ActionResult Add(CUSTOMCITY model) { try { ICityService svc = new CityService(); var result = svc.Add(model); this.AddNotification("Your Data Has Been Successfully Saved. ", NotificationType.SUCCESS); return(RedirectToAction("Index")); } catch (Exception ex) { general.AddLogError("City Add", ex.Message, ex.StackTrace); this.AddNotification("ID exist", NotificationType.ERROR); this.ViewBag.Status = new SelectList(this.GetStatus(), "Key", "Value"); return(View("~/Views/Master/City/Add.cshtml")); } }
public ActionResult Add(City data) { _cityService.Add(data); return(Redirect("/Admin/Category/List")); }