Example #1
0
        public void Save(Product entity)
        {
            ValidationResultInfo vri = Validate(entity);
            if (!vri.IsValid)
                throw new DomainValidationException(vri, "Product  Details not Valid");
            DateTime date = DateTime.Now;
            Product tbl = _context.Products.FirstOrDefault(s => s.Id == entity.Id);
            if (tbl == null)
            {
                tbl = new Product();
                tbl.CreatedOn = date;
                tbl.IsActive = true;

                tbl.Id = entity.Id;
                _context.Products.Add(tbl);
            }
            tbl.Name = entity.Name;
            tbl.AccountId = entity.AccountId;
            tbl.UpdatedOn = date;
            tbl.CategoryId = entity.CategoryId;
            tbl.Description = entity.Description;
            tbl.BuyingPrice = entity.BuyingPrice;
            tbl.SellingPrice = entity.SellingPrice;
            _context.SaveChanges();
        }
        private static ProductDTO Map(Product s)
        {
            return new ProductDTO
               {
               Id = s.Id,
               Name = s.Name,
               IsActive = s.IsActive,
               AccountId = s.AccountId,
               Description = s.Description,
               BuyingPrice = s.BuyingPrice,
               SellingPrice = s.SellingPrice,
               CategoryId = s.CategoryId,

               };
        }
        public BasicResponse AddProduct(ProductDTO dto)
        {
            BasicResponse response = new BasicResponse();
               try
               {
               var account = new Product()
               {
                   Name = dto.Name,
                   Id = dto.Id,
                   AccountId = dto.AccountId,
                   Description = dto.Description,
                   IsActive = true,
                   CreatedOn = DateTime.Now,
                   UpdatedOn = DateTime.Now,
                   CategoryId = dto.CategoryId,
                   BuyingPrice = dto.BuyingPrice,
                   SellingPrice = dto.SellingPrice,
               };

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

               }
               catch (Exception ex)
               {

               response.Status = false;
               response.Info = ex.Message;
               }
               return response;
        }
Example #4
0
 public ValidationResultInfo Validate(Product itemToValidate)
 {
     return itemToValidate.BasicValidation();
 }
Example #5
0
        protected Product AddProduct()
        {
            var productRepository = IocHelper.Using<IProductRepository>();
            var account = AddAccount();
            var category = AddCategory();
            Product entity = new Product()
            {
                IsActive = true,
                CreatedOn = DateTime.Now,
                Id = Guid.NewGuid(),
                Name = TestString(),
                Account = account,
                AccountId = account.Id,
                Description = TestString(),
                UpdatedOn = DateTime.Now,
                BuyingPrice = 300,
                Category = category,
                CategoryId = category.Id,
                SellingPrice = 400,

            };
            productRepository.Save(entity);
            return productRepository.GetById(entity.Id);
        }
Example #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();
        }