示例#1
0
        protected Category AddCategory()
        {
            var categoryRepository = IocHelper.Using<ICategoryRepository>();
            var account = AddAccount();
            Category entity = new Category()
            {
                IsActive = true,
                CreatedOn = DateTime.Now,
                Id = Guid.NewGuid(),
                Name = TestString(),
                Account = account,
                AccountId = account.Id,
                Description = TestString(),
                UpdatedOn = DateTime.Now,

            };
            categoryRepository.Save(entity);
            return categoryRepository.GetById(entity.Id);
        }
示例#2
0
        public void Save(Category entity)
        {
            ValidationResultInfo vri = Validate(entity);
            if (!vri.IsValid)
                throw new DomainValidationException(vri, "Category  Details not Valid");
            DateTime date = DateTime.Now;
            Category tbl = _context.Categories.FirstOrDefault(s => s.Id == entity.Id);
            if (tbl == null)
            {
                tbl = new Category();
                tbl.CreatedOn = date;
                tbl.IsActive = true;

                tbl.Id = entity.Id;
                _context.Categories.Add(tbl);
            }
            tbl.Name = entity.Name;
            tbl.AccountId = entity.AccountId;
            tbl.UpdatedOn = date;
            tbl.Description = entity.Description;
            _context.SaveChanges();
        }
        public BasicResponse AddCategory(CategoryDTO dto)
        {
            BasicResponse response = new BasicResponse();
               try
               {
               var account = new Category()
               {
                   Name = dto.Name,
                   Id = dto.Id,
                   AccountId = dto.AccountId,
                   Description = dto.Description,

                   IsActive = true,
                   CreatedOn = DateTime.Now,
                   UpdatedOn = DateTime.Now,

               };

               _categoryRepository.Save(account);
               response.Status = true;
               response.Info = "Success";

               }
               catch (Exception ex)
               {

               response.Status = false;
               response.Info = ex.Message;
               }
               return response;
        }
        private static CategoryDTO Map(Category s)
        {
            return new CategoryDTO
               {
               Id = s.Id,
               Name = s.Name,
               IsActive = s.IsActive,
               AccountId = s.AccountId,
               Description = s.Description,

               };
        }
示例#5
0
 public ValidationResultInfo Validate(Category itemToValidate)
 {
     return itemToValidate.BasicValidation();
 }
示例#6
0
        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();
        }