public IActionResult Save(UnitBindingModel model) { if (!ModelState.IsValid) { DateTime?createdOn = (DateTime?)null; var createdBy = string.Empty; DateTime?lastUpdatedOn = (DateTime?)null; var lastUpdatedBy = string.Empty; var buildingName = string.Empty; if (model.UnitId > 0) { var u = _unitRepository.GetUnit(model.UnitId); createdOn = u.CreatedOn; createdBy = u.CreatedByName; lastUpdatedOn = u.LastUpdatedOn; lastUpdatedBy = u.LastUpdatedByName; buildingName = u.BuildingName; } return(View("Edit", new UnitViewModel { UnitId = model.UnitId, CreatedOn = createdOn, CreatedBy = createdBy, LastUpdatedOn = lastUpdatedOn, LastUpdatedBy = lastUpdatedBy, UnitName = model.UnitName, BuildingName = buildingName, SquareFootage = model.SquareFootage, NumberOfBedrooms = model.NumberOfBedrooms, NumberOfBathrooms = model.NumberOfBathrooms })); } var unit = new Unit(); if (model.UnitId > 0) { unit = _unitRepository.GetUnit(model.UnitId); } unit.UnitName = model.UnitName; unit.SquareFootage = model.SquareFootage; unit.NumberOfBedrooms = model.NumberOfBedrooms; unit.NumberOfBathrooms = model.NumberOfBathrooms; if (model.UnitId > 0) { _unitRepository.UpdateUnit(unit); } else { _unitRepository.AddUnit(unit); } return(RedirectToAction("Index")); }
public async Task <Unit> AddUnit(Unit unit) { try { return(await _unitRepository.AddUnit(unit)); } catch (Exception exception) { throw exception; } }
public void Post(Models.UnitBindingModel model) { var unit = new Unit(); unit.UnitName = model.UnitName; unit.BuildingId = model.BuildingId; unit.SquareFootage = model.SquareFootage; unit.NumberOfBedrooms = model.NumberOfBedrooms; unit.NumberOfBathrooms = model.NumberOfBathrooms; _unitRepository.AddUnit(unit); }
public HttpResponseMessage Post([FromBody] Models.unit unit) { try { if (string.IsNullOrEmpty(unit.unit_name)) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = "Unit is Empty" }, formatter)); } else { unit insert_unit = new unit { unit_name = unit.unit_name }; /* user table entry by rabby*/ unitRepository.AddUnit(insert_unit); /* user table entry by rabby*/ var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "success", msg = "Unit save successfully" }, formatter)); } } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = ex.ToString() }, formatter)); } }
// Add unit. public bool AddUnit(Unit unit) { return(_unitRepository.AddUnit(unit)); }
public void AddUnit(Unit unit) { _unitRepository.AddUnit(unit); }