Exemple #1
0
        public ActionResult Create([Bind(Include = "Id,Name")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,Notes,Cost,TypeId,CategoryId")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", item.CategoryId);
            ViewBag.TypeId     = new SelectList(db.Types, "Id", "Name", item.TypeId);
            return(View(item));
        }
        public void Add(DTOProduct model)
        {
            try
            {
                Product product = _mapper.Map <Product>(model);
                if (model.BrandId > 0 && model.CategoryId > 0)
                {
                    product.CategoryBrandId = _context.CategoriesBrands.Where(x => x.BrandId == model.BrandId && x.CategoryId == model.CategoryId).Select(x => x.Id).FirstOrDefault();
                }

                ProductPrice            productPrice      = _mapper.Map <ProductPrice>(model.ProductPrice);
                List <ProductAttribute> productAttributes = _mapper.Map <List <ProductAttribute> >(model.ProductAttributeList);
                List <ProductShelf>     productShelves    = _mapper.Map <List <ProductShelf> >(model.productInventoryList);


                _context.Products.Add(product);
                _context.SaveChanges();
                productPrice.ProductId = product.Id;

                if (productPrice != null)
                {
                    _context.ProductPrices.Add(productPrice);
                }

                if (productAttributes != null)
                {
                    foreach (var attr in productAttributes)
                    {
                        attr.ProductId = product.Id;
                    }

                    _context.ProductAttributes.AddRange(productAttributes);
                }

                if (productShelves != null)
                {
                    foreach (var prodShelf in productShelves)
                    {
                        prodShelf.ProductId = product.Id;
                    }

                    _context.ProductShelves.AddRange(productShelves);
                }

                _context.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        void IInventoryService.Add(DTOInventory inventory)
        {
            PhoneNumber phone   = inventory.PhoneNumber;
            Address     address = _mapper.Map <Address>(inventory.Address);
            Inventory   i       = _mapper.Map <Inventory>(inventory);

            _context.Add(phone);
            _context.Add(address);
            _context.SaveChanges();

            i.PhoneNumberId = phone.Id;
            i.AddressId     = address.Id;
            _context.Add(i);
            _context.SaveChanges();
        }
        public void Add_user_to_database()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();
            try
            {
                // Connection
                var options = new DbContextOptionsBuilder <IMSContext>().UseSqlite(connection).Options;
                using (var context = new IMSContext(options))
                {
                    context.Database.EnsureCreated();
                }
                // insert data
                using (var context = new IMSContext(options))
                {
                    var service = new UserService(context);
                    service.AddUser("jihoson", "123", "*****@*****.**");
                    context.SaveChanges();
                }
                // validation
                using (var context = new IMSContext(options))
                {
                    Assert.Equal(1, context.Users.Count());
                }
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #6
0
        public StudentEntity Create(StudentEntity StudentEntity)
        {
            Student student = StudentEntity.ToModel();

            IMSContext.Students.Add(student);
            IMSContext.SaveChanges();
            return(new StudentEntity(IMSContext.Students.Where(s => s.Id == student.Id).FirstOrDefault()));
        }
Exemple #7
0
        public InternFollowEntity Create(UserEntity UserEntity, InternFollowEntity InternFollowEntity)
        {
            InternFollow InternFollow = InternFollowEntity.ToModel();

            IMSContext.InternFollows.Add(InternFollow);
            IMSContext.SaveChanges();
            return(InternFollowEntity);
        }
Exemple #8
0
        public AdminEntity Update(UserEntity userEntity, Guid Id, AdminEntity adminEntity)
        {
            Admin admin = IMSContext.Admins.Where(a => a.Id == Id).FirstOrDefault();

            adminEntity.ToModel(admin);
            IMSContext.SaveChanges();
            return(adminEntity);
        }
Exemple #9
0
        public LecturerFollowEntity Update(UserEntity UserEntity, Guid LecturerId, LecturerFollowEntity LecturerFollowEntity)
        {
            LecturerFollow LecturerFollow = IMSContext.LecturerFollows.Where(l => l.Id == LecturerId).FirstOrDefault();

            LecturerFollowEntity.ToModel(LecturerFollow);
            IMSContext.SaveChanges();
            return(null);
        }
Exemple #10
0
        public LecturerFollowEntity Create(UserEntity UserEntity, LecturerFollowEntity LecturerFollowEntity)
        {
            LecturerFollow LecturerFollow = LecturerFollowEntity.ToModel();

            IMSContext.LecturerFollows.Add(LecturerFollow);
            IMSContext.SaveChanges();
            return(LecturerFollowEntity);
        }