/// <summary> /// Update New Child /// </summary> public object UpdateChild(ChildData childData) { using (var context = new CustomerInfoRepository()) { var updating = context.Childrens.FirstOrDefault(x => x.Id == childData.Id); if (updating != null) { updating.Updated = DateTime.UtcNow; if (childData.Name != null) updating.Name = childData.Name; if (childData.Avatar != null) updating.Avatar = childData.Avatar; if (childData.Obs != null) updating.Obs = childData.Obs; if (childData.Category != null) updating.Category = childData.Category; try { context.SaveChanges(); return updating; } catch (Exception) { return null; } } else { return null; } } }
public void UpdateChild() { var repository = new CustomerRepositoryHelper(); var childData = new ChildData { Id = 1, LicenseId = "12345", Name = "Sergei1", Avatar = "oak1", Obs = "1", Category = "category1" }; Console.WriteLine(repository.UpdateChild(childData)); }
/// <summary> /// Create New Child /// </summary> public Boolean InsertChild(ChildData childData) { var child = new Child { LicenseId = childData.LicenseId, Name = childData.Name, Avatar = childData.Avatar, Obs = childData.Obs, Category = childData.Category, Created = DateTime.UtcNow, Updated = DateTime.UtcNow, Version = "1.0" }; using (var context = new CustomerInfoRepository()) { context.Childrens.Add(child); try { context.SaveChanges(); return true; } catch (Exception) { return false; } } }
public void InsertChildTest() { var repository = new CustomerRepositoryHelper(); var childData = new ChildData { LicenseId = "1234", Name = "Roman", Avatar = "eagle", Obs = "", Category = "category" }; Console.WriteLine(repository.InsertChild(childData)); }