Esempio n. 1
0
        public IActionResult Post(CustomEmployee model)
        {
            var countryId = from c in db.Country
                            where c.country_name == model.country_name
                            select c.id;

            if (model.id != 0)
            {
                Employee employee = db.Employees.Where(x => x.id == model.id).FirstOrDefault();
                employee.name       = model.name;
                employee.job_title  = model.job_title;
                employee.gender     = model.gender;
                employee.email      = model.email;
                employee.phone_no   = model.phone_no;
                employee.address    = model.address;
                employee.country_id = countryId.FirstOrDefault();
                db.SaveChanges();
                return(Ok(2));
            }
            else
            {
                Employee employee = new Employee();
                employee.name       = model.name;
                employee.job_title  = model.job_title;
                employee.gender     = model.gender;
                employee.email      = model.email;
                employee.phone_no   = model.phone_no;
                employee.address    = model.address;
                employee.country_id = countryId.FirstOrDefault();
                db.Add(employee);
                db.SaveChanges();

                return(Ok(1));
            }
        }
        public async Task <int> Create(ProductCreateRequest request)
        {
            var product = new products()
            {
                idSize         = request.idSize,
                idBrand        = request.idBrand,
                idCategory     = request.idCategory,
                idColor        = request.idColor,
                idType         = request.idType,
                ViewCount      = 0,
                productDetails = new List <productDetail>()
                {
                    new productDetail()
                    {
                        ProductName = request.ProductName,
                        price       = request.price,
                        salePrice   = request.salePrice,
                        detail      = request.detail,
                        dateAdded   = DateTime.Now,
                    }
                }
            };

            //Save image
            if (request.ThumbnailImage != null)
            {
                product.productPhotos = new List <productPhotos>()
                {
                    new productPhotos()
                    {
                        Caption      = "Thumbnail image",
                        uploadedTime = DateTime.Now,
                        FileSize     = request.ThumbnailImage.Length,
                        ImagePath    = await this.SaveFile(request.ThumbnailImage),
                        IsDefault    = true,
                    }
                };
            }
            _context.Add(product);
            await _context.SaveChangesAsync();

            return(product.idProduct);
        }
Esempio n. 3
0
        public IActionResult Post(ApplicationUserModel model)
        {
            var user = db.applicationUsers.Where(x => x.name == model.name).FirstOrDefault();

            if (user == null)
            {
                ApplicationUser applicationUser = new ApplicationUser();
                applicationUser.name         = model.name;
                applicationUser.email        = model.email;
                applicationUser.password     = model.password;
                applicationUser.created_date = DateTime.Now;
                applicationUser.updated_date = DateTime.Now;
                db.Add(applicationUser);
                db.SaveChanges();
                return(Ok(true));
            }
            else
            {
                return(Ok(false));
            }
        }