public ActionResult Edit(int id) { try { ViewBag.Saved = false; PropertyTypeModel mbt = new PropertyTypeModel() { PropertyTypeId = 0 }; CLayer.PropertyType pt = BLayer.PropertyType.Get(id); if (pt != null) { mbt = new PropertyTypeModel() { PropertyTypeId = pt.PropertyTypeId, Title = pt.Title } } ; return(PartialView("_Edit", mbt)); } catch (Exception ex) { Common.LogHandler.HandleError(ex); return(Redirect("~/Admin/ErrorPage")); } }
private void UpdatePropertyTypeFromModel(PropertyType target, PropertyTypeModel source) { target.PropertyTypeId = source.PropertyTypeId; target.PropertyTypeGuid = source.PropertyTypeGuid; target.PropertyTypeText = source.PropertyTypeText; target.PropertyTypeIsActive = source.PropertyTypeIsActive; }
public ActionResult Edit(PropertyTypeModel data) { try { if (ModelState.IsValid) { CLayer.PropertyType pt = new CLayer.PropertyType() { PropertyTypeId = data.PropertyTypeId, Title = data.Title }; BLayer.PropertyType.Save(pt); ViewBag.Saved = true; } else { ViewBag.Saved = false; } return(RedirectToAction("Index")); } catch (Exception ex) { Common.LogHandler.HandleError(ex); return(Redirect("~/Admin/ErrorPage")); } }
public async Task <PropertyTypeModel> AddAsync(PropertyTypeModel propertyType, CancellationToken ct = default) { Ensure.IsNotNull(propertyType, nameof(propertyType)); _context.PropertyTypeModel.Add(propertyType); await _context.SaveChangesAsync(ct); return(propertyType); }
public static PropertyTypeModel DataReader_to_PropertyTypeModel(SqlDataReader reader) { PropertyTypeModel propertyType = new PropertyTypeModel(); propertyType.PropertyTypeID = (Guid)reader["PropertyTypeID"]; propertyType.PropertyTypeName = (String)reader["PropertyTypeName"]; propertyType.PropertyTypeNameKey = (String)reader["PropertyTypeNameKey"]; propertyType.PropertyTypeDescription = (String)reader["PropertyTypeDescription"]; return(propertyType); }
public async Task <int> DeletePropertyTypeAsync(PropertyTypeModel model) { var propertyType = new PropertyType { PropertyTypeId = model.PropertyTypeId }; using (var dataService = DataServiceFactory.CreateDataService()) { return(await dataService.DeletePropertyTypeAsync(propertyType)); } }
static public async Task <PropertyTypeModel> CreatePropertyTypeModelAsync(PropertyType source, bool includeAllFields) { var model = new PropertyTypeModel() { PropertyTypeId = source.PropertyTypeId, PropertyTypeGuid = source.PropertyTypeGuid, PropertyTypeText = source.PropertyTypeText, PropertyTypeIsActive = source.PropertyTypeIsActive, }; return(model); }
public async Task <bool> UpdateAsync(PropertyTypeModel input, CancellationToken ct = default) { var result = false; Ensure.IsNotNull(input, nameof(input)); if (await IsPropertyTypExists(input.Id)) { _context.PropertyTypeModel.Update(input); await _context.SaveChangesAsync(ct); result = true; } return(result); }
public void PropertyTypeHandler_UpdateAsync_Returns_PropertyTypeModel_When_InputIsValid() { var propertyTypeModel = new PropertyTypeModel { Id = 1, Name = "Free" }; var propertyRepository = new Mock <IPropertyRepository>(); var propertyTypeHandler = new PropertyTypeHandler(propertyRepository.Object); propertyRepository.Setup(x => x.UpdateAsync(It.IsAny <PropertyTypeModel>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(true)); var result = propertyTypeHandler.UpdateAsync(propertyTypeModel.Convert()); Assert.IsInstanceOf(typeof(bool), true); }
public void PropertyTypeHandler_GetByIdAsync_Returns_PropertyTypeModel_When_InputIsValid() { var propertyTypeModel = new PropertyTypeModel { Id = 1, Name = "Free" }; var propertyRepository = new Mock <IPropertyRepository>(); var propertyTypeHandler = new PropertyTypeHandler(propertyRepository.Object); propertyRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(propertyTypeModel)); var result = propertyTypeHandler.GetByIdAsync(1); Assert.IsTrue(result.Result.Id == 1); Assert.IsTrue(result.Result.Name == "Free"); }
public async Task <PropertyTypeModel> UpdatePropertyTypeAsync(PropertyTypeModel model) { long id = model.PropertyTypeId; using (var dataService = DataServiceFactory.CreateDataService()) { var propertyType = id > 0 ? await dataService.GetPropertyTypeAsync(model.PropertyTypeId) : new PropertyType(); if (propertyType != null) { UpdatePropertyTypeFromModel(propertyType, model); await dataService.UpdatePropertyTypeAsync(propertyType); model.Merge(await GetPropertyTypeAsync(dataService, propertyType.PropertyTypeId)); } return(model); } }