コード例 #1
0
        public async Task <IActionResult> PutUser([FromRoute] string id, [FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <Claim> InsertAsync(Claim claim)
        {
            _context.Claims.Add(claim);
            await _context.SaveChangesAsync();

            return(claim);
        }
コード例 #3
0
        private async Task <bool> removePaymentResource(dal.Entities.ReceiptDetailType receiptDetailType, Guid idResource, bool saveChanges = true)
        {
            switch (receiptDetailType)
            {
            case dal.Entities.ReceiptDetailType.Fee:
                //something to do? maybe
                break;

            case dal.Entities.ReceiptDetailType.Other:
                //something to do? maybe
                break;

            case dal.Entities.ReceiptDetailType.Product:
                var item = _dbCtx.CustomerProductInstances.Find(idResource);
                if (item != null)
                {
                    //item.IdReceipt = null;
                    //item.PaymentStatus = dal.Entities.PaymentStatus.None;
                    _dbCtx.CustomerProductInstances.Remove(item);
                    if (saveChanges)
                    {
                        await _dbCtx.SaveChangesAsync();
                    }
                }
                break;
            }
            return(true);
        }
コード例 #4
0
        public async Task <IActionResult> Add(Employee employee, string NameImage, string NameFolder)
        {
            var info = HttpContext.Session.GetObject <Employee>("Employee");

            if (info == null)
            {
                return(BadRequest(new { message = "login" }));
            }
            if (ModelState.IsValid && employee != null)
            {
                bool check = _context.Employee.Any(e => e.UserName == employee.UserName);
                if (!check)
                {
                    MyTool.MoveImage("Employee", NameImage, NameFolder);
                    employee.Image       = NameImage;
                    employee.CreatedDate = DateTime.Now;
                    employee.Password    = MyHashTool.GetMd5Hash(employee.Password);

                    _context.Employee.Add(employee);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    return(BadRequest(new { content = "Tài khoản đã tồn tại!!!" }));
                }
            }
            else
            {
                return(BadRequest(new { content = "Vui lòng điền thông tin tài khoản!" }));
            }

            var model = await _context.Employee.AsNoTracking().ToListAsync();

            return(View("Datatable", model));
        }
コード例 #5
0
ファイル: PostsController.cs プロジェクト: bruce588/Demo
        public async Task <IActionResult> PutPosts(int id, Posts posts)
        {
            if (id != posts.PostId)
            {
                return(BadRequest());
            }

            _context.Entry(posts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #6
0
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            employee.Id = id;

            _context.Entry(employee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #7
0
        public async Task <Product> PostProduct(ProductPostRequest product)
        {
            var productAdded = _mapper.Map <Product>(product);

            productAdded.createdDate = productAdded.updatedDate = DateTime.Now;

            if (product.ImageFiles != null)
            {
                foreach (IFormFile file in product.ImageFiles)
                {
                    productAdded.Images.Add(new Image {
                        productId = productAdded.productId, imageUrl = await _filesService.SaveFilePath(file)
                    });
                }
            }
            try
            {
                _context.Add(productAdded);
                await _context.SaveChangesAsync();

                var productAdded4Real = await GetProductByID(productAdded.productId);

                return(productAdded4Real);
            }
            catch (System.Exception e)
            {
                return(null);
            }
        }
コード例 #8
0
        public async Task <IActionResult> PutSeccion([FromRoute] int id, [FromBody] Seccion seccion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != seccion.seccionID)
            {
                return(BadRequest());
            }

            _context.Entry(seccion).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SeccionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(seccion));
        }
コード例 #9
0
 public async Task <IActionResult> Create([Bind("Ffile")] IFormFile Ffile, [Bind(" ProductName,Unit,UrlFriendly,Description,Price,PromotionPrice,IncludeVat,Quantity,CategoryId,PublisherId,Discount,ViewCounts,Status")] Product product, List <IFormFile> fFiles)
 {
     if (ModelState.IsValid)
     {
         try
         {
             //thêm ảnh bìa
             product.ImageCover = UploadAnhBia(Ffile);
             //Thêm product vào db
             _context.Add(product);
             _context.SaveChanges();
             //thêm hình ảnh mô tả
             UploadAnhMoTa(fFiles, product.ProductId);
             ViewBag.Message = "Thêm sản phẩm thành công !!!";
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             ViewBag.Message = "Thêm sản phẩm thất bại !!!";
         }
     }
     ViewData["CategoryId"]  = new SelectList(_context.ProductCategory, "CategoryId", "CategoryId", product.CategoryId);
     ViewData["PublisherId"] = new SelectList(_context.Publishers, "PublisherId", "PublisherName", product.PublisherId);
     return(View());
 }
コード例 #10
0
        public async Task <ActionResult <bool> > PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(false);
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }

            return(true);
        }
コード例 #11
0
        public async Task <IActionResult> PutCustomer(long id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #12
0
        public async Task <ActionResult <Task> > PutTask(int id, [FromBody] Task task)
        {
            if (id != task.Id)
            {
                return(BadRequest());
            }

            _context.Entry(task).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(Ok(task));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return(BadRequest());
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #13
0
        public async Task <IHttpActionResult> PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #14
0
ファイル: GenericRepository.cs プロジェクト: ldalmolin/webapi
        public async virtual Task <T> AddAsync(T entity)
        {
            _context.Set <T>().Add(entity);
            await _context.SaveChangesAsync();

            return(entity);
        }
        public async Task <IActionResult> Create(GuestViewModel guestViewModel)
        {
            if (ModelState.IsValid)
            {
                Guest guest = new Guest
                {
                    _guestName  = guestViewModel.GuestName,
                    _guestEmail = guestViewModel.GuestEmail,
                    _guestPhone = guestViewModel.GuestPhone
                };
                _context.Add(guest);

                DateTime leaving = guestViewModel.arrival.AddHours(3);

                List <Table> TablesForThisReservation = _tableManager.GetOptimalTableConfig(guestViewModel.arrival, leaving, guestViewModel.size);

                Reservation currentRes = new Reservation(guestViewModel.size, guestViewModel.arrival, 3, guest);
                _context.Reservations.Add(currentRes);

                foreach (Table table in TablesForThisReservation)
                {
                    _context.ReservationTableCouplings.Add(new ReservationTableCoupling(currentRes, table));
                }



                await _context.SaveChangesAsync();

                return(RedirectToAction("ConfirmReservation", "Home"));
            }
            return(View());
        }
コード例 #16
0
        public async Task <IActionResult> PutEmail(string id, Email email)
        {
            email.id = id;


            _context.Entry(email).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #17
0
        public async Task <ShopBridgeItemModel> Create(ShopBridgeItemModel model)
        {
            DBContext.Set <ShopBridgeItemModel>().Add(model);
            await DBContext.SaveChangesAsync();

            return(model);
        }
コード例 #18
0
        public async Task <IActionResult> PutArticle(int id, Article article)
        {
            if (id != article.Id)
            {
                return(BadRequest());
            }

            _context.Entry(article).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #19
0
        public async Task <AppResult> Register([FromBody] LoginDto model)
        {
            if (model == null ||
                string.IsNullOrWhiteSpace(model.UserName) ||
                string.IsNullOrWhiteSpace(model.Password))
            {
                return(ErrorMessage("Error"));
            }


            var u = await _dbContext.Users.SingleOrDefaultAsync(x =>
                                                                x.UserName == model.UserName &&
                                                                x.Password == model.Password);

            if (u != null)
            {
                return(ErrorMessage("user  exist"));
            }

            var dbUser = new User
            {
                UserName = model.UserName,
                Password = model.Password
            };

            _dbContext.Users.Add(dbUser);
            await _dbContext.SaveChangesAsync();

            var data = await BuidlCredentials(model, dbUser.UserId);

            return(SuccessfullMessage(data));
        }
コード例 #20
0
        public async Task <IActionResult> PutDNagroda(string id, DNagroda dNagroda)
        {
            dNagroda.id = id;


            _context.Entry(dNagroda).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DNagrodaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #21
0
        public async Task <IActionResult> PutDZguba_Elektronika(int id, DZguba_Elektronika dZguba_Elektronika)
        {
            dZguba_Elektronika.id = id;

            dZguba_Elektronika.UpdatedDate           = DateTime.Now;
            _context.Entry(dZguba_Elektronika).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DZguba_ElektronikaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #22
0
        public async Task <IActionResult> PutMulta([FromRoute] int id, [FromBody] Contrato contrato)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contrato.ID)
            {
                return(BadRequest());
            }

            _context.Entry(contrato).State = EntityState.Modified;

            try
            {
                await CrearOEditarMulta(contrato.multas);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContratoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(contrato));
        }
コード例 #23
0
        public async Task <IActionResult> Put(int id, [FromBody] EXPMaster _EXPMaster)
        {
            if (id != _EXPMaster.Id)
            {
                return(BadRequest());
            }

            _context.Entry(_EXPMaster).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EXPMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #24
0
ファイル: WidgetController.cs プロジェクト: mjabdi/CmeAPI4
        public async Task <IActionResult> Post([FromBody] WidgetDTO widget)
        {
            AuthController.ValidateAndGetCurrentUserName(this.HttpContext.Request);

            if (widget == null)
            {
                return(NotFound());
            }

            string email = widget.Email;

            try
            {
                Widget oldwgt = await context.Widgets.FirstOrDefaultAsync(w => w.UserID == email &&
                                                                          w.WidgetName == widget.WidgetName);

                if (oldwgt != null)
                {
                    return(BadRequest("DuplicateName"));
                }

                Widget wgt = new Widget(widget, context);
                context.Widgets.Add(wgt);
                await context.SaveChangesAsync();

                EmailManager.SendCreationWidgetNotification(wgt);

                return(Ok(new { Token = wgt.ID }));
            }catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #25
0
        public async Task <IActionResult> PutTipsForEveryOne([FromRoute] Guid id, [FromBody] TipsForEveryOne tipsForEveryOne)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tipsForEveryOne.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tipsForEveryOne).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TipsForEveryOneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #26
0
        public IActionResult Save([FromBody] UserInfo value)
        {
            _context.UserInfo.Update(value);
            _context.SaveChangesAsync();

            return(Ok(value));
        }
コード例 #27
0
        public async Task <IActionResult> PutPago([FromRoute] int id, [FromBody] Pago pago)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pago.ID)
            {
                return(BadRequest());
            }

            _context.Entry(pago).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PagoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #28
0
        public async Task <IActionResult> PutArticles([FromRoute] Guid id, [FromBody] ArticlesDTO articles)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != articles.Id)
            {
                return(BadRequest());
            }

            _context.Entry(articles).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArticlesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #29
0
        public async Task <ActionResult> Post([FromBody] Customer customer)
        {
            await myDBContext.Customers.AddAsync(customer);

            await myDBContext.SaveChangesAsync();

            return(Ok(customer));
        }
コード例 #30
0
        public async Task <ActionResult> Post([FromBody] Category category)
        {
            await myDBContext.Categories.AddAsync(category);

            await myDBContext.SaveChangesAsync();

            return(Ok(category));
        }