public kupah ConvertModelToEntity(KupahModel model, int userId = -1) { kupah entity = new kupah(); if (model == null) { return(null); } entity.name = model.Name; entity.isCurrent = model.IsCurrent; entity.isDefault = model.IsDefault; entity.isPrivate = model.IsPrivate; if (model.Id > 0) { entity.id = model.Id; } if (userId > 0) { if (entity.id > 0) { entity.editedById = userId; entity.editedByDate = System.DateTime.Now; } else //entity.id <= 0 { entity.createdById = userId; entity.createdByDate = System.DateTime.Now; } } return(entity); }
public KupahModel GetDefault() { kupah entity = this._repository.GetDefault(); KupahModel model = this.ConvertEntityToModel(entity); return(model); }
public KupahModel GetById(int id) { kupah entity = this._repository.GetById(id); KupahModel model = this.ConvertEntityToModel(entity); return(model); }
public IHttpActionResult Post(KupahModel model, int userId) { try { int result = _service.Insert(model, userId); return(Ok(result)); } catch (Exception ex) { return(BadRequest(ex.Message.ToString())); } }
public void GetDefault_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var repository = new KupahRepository(context); var service = new KupahService(repository); // Act KupahModel result = service.GetDefault(); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.IsDefault); }
private KupahModel GetDemoItem(bool isNew) { KupahModel item = new KupahModel() { Name = "Demo name", IsCurrent = true, IsDefault = false }; if (!isNew) { item.Id = 1; } return(item); }
public void GetById_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var repository = new KupahRepository(context); var service = new KupahService(repository); int id = 1; // Act KupahModel result = service.GetById(id); // Assert Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); }
public void ConvertModelToEntity_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var service = new KupahService(); KupahModel model = GetTestModel(); // Act kupah entity = service.ConvertModelToEntity(model); // Assert Assert.IsNotNull(entity); Assert.AreEqual(entity.name, model.Name); Assert.AreEqual(entity.isDefault, model.IsDefault); Assert.AreEqual(entity.isCurrent, model.IsCurrent); Assert.AreEqual(entity.isPrivate, model.IsPrivate); }
public void ConvertEntityToModel_Test() { // Arrange TestKolgraphEntities context = new TestKolgraphEntities(); var service = new KupahService(); kupah entity = context.kupah.Where(x => x.id == 1).FirstOrDefault(); // Act KupahModel model = service.ConvertEntityToModel(entity); // Assert Assert.IsNotNull(model); Assert.AreEqual(model.Id, entity.id); Assert.AreEqual(model.Name, entity.name); Assert.AreEqual(model.IsDefault, entity.isDefault); Assert.AreEqual(model.IsCurrent, entity.isCurrent); }
public KupahModel ConvertEntityToModel(kupah entity) { if (entity == null) { return(null); } var model = new KupahModel() { Id = entity.id, Name = entity.name.Trim(), IsCurrent = entity.isCurrent, IsDefault = entity.isDefault, IsPrivate = entity.isPrivate }; return(model); }
public int Update(KupahModel model, int userId) { kupah entity = this.ConvertModelToEntity(model, userId); return(this._repository.Update(entity)); }
public IHttpActionResult Put(KupahModel model, int userId) { int result = _service.Update(model, userId); return(Content(System.Net.HttpStatusCode.Accepted, model)); }