public void Save(Route entity) { ValidationResultInfo vri = Validate(entity); if (!vri.IsValid) throw new DomainValidationException(vri, "Route Details not Valid"); DateTime date = DateTime.Now; Route tbl = _context.Routes.FirstOrDefault(s => s.Id == entity.Id); if (tbl == null) { tbl = new Route(); tbl.CreatedOn = date; tbl.IsActive = true; tbl.Id = entity.Id; _context.Routes.Add(tbl); } tbl.Name = entity.Name; tbl.UpdatedOn = date; tbl.Code = entity.Code; tbl.Account = entity.Account; tbl.AccountId = entity.AccountId; _context.SaveChanges(); }
public ValidationResultInfo Validate(Route itemToValidate) { return itemToValidate.BasicValidation(); }
protected Route AddRoute() { var routeRepository = IocHelper.Using<IRouteRepository>(); var account = AddAccount(); Route entity = new Route() { IsActive = true, CreatedOn = DateTime.Now, Id = Guid.NewGuid(), Name = TestString(), Account = account, AccountId = account.Id, UpdatedOn = DateTime.Now, Code = TestString(), }; routeRepository.Save(entity); return routeRepository.GetById(entity.Id); }
private static RouteDTO Map(Route s) { return new RouteDTO { Id = s.Id, Name = s.Name, Code = s.Code, IsActive = s.IsActive, AccountId = s.AccountId }; }
protected void Seed(SafAppDbContext context) { Country country = new Country { Code = "KE", CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Kenya", ZipCode = "+254" }; context.Countries.Add(country); Account account = new Account { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Test Account", }; context.Accounts.Add(account); var user1 = new User { CreatedOn = DateTime.Now, Email = "*****@*****.**", Fullname = "Juvenalis Gitau", Id = Guid.NewGuid(), IsActive = true, Password = Md5Hash.GetMd5Hash("1234"), PhoneNumber = "0722557538", UpdatedOn = DateTime.Now, Username = "******", UserType = UserType.Admin, Account = account }; context.Users.Add(user1); var user2 = new User { CreatedOn = DateTime.Now, Email = "*****@*****.**", Fullname = "Patrick Munene", Id = Guid.NewGuid(), IsActive = true, Password = Md5Hash.GetMd5Hash("1234"), PhoneNumber = "0000000000", UpdatedOn = DateTime.Now, Username = "******", UserType = UserType.Admin, Account = account }; context.Users.Add(user2); var category = new Category { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Sugar", Description = "Sugar", Account = account }; context.Categories.Add(category); var product1 = new Product() { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Mumias Sugar 1Kg", Account = account, Category = category, BuyingPrice = 20, SellingPrice = 30, Description = "Sugar" }; context.Products.Add(product1); var product2 = new Product() { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Sony Sugar 1Kg", Account = account, Category = category, BuyingPrice = 20, SellingPrice = 30, }; context.Products.Add(product2); var route = new Route() { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Kilimani", Account = account, AccountId = account.Id, Code = "R001" }; context.Routes.Add(route); var outlet = new Outlet() { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Outlet Yaya", Account = account, AccountId = account.Id, Code = "O001", Latitude = 31.22, Longitude = 1.22, Route = route, RouteId = route.Id }; context.Outlets.Add(outlet); var outlet1 = new Outlet() { CreatedOn = DateTime.Now, Id = Guid.NewGuid(), IsActive = true, UpdatedOn = DateTime.Now, Name = "Outlet Ronga", Account = account, AccountId = account.Id, Code = "O002", Latitude = 31.32, Longitude = 1.32, Route = route, RouteId = route.Id }; context.Outlets.Add(outlet1); context.SaveChanges(); }