コード例 #1
0
        public async Task <IActionResult> PutLandmarks(int id, Landmark landmarks)
        {
            if (id != landmarks.Landmark_Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
ファイル: BankController.cs プロジェクト: g0dgamerz/ngc-curd
        public async Task <IActionResult> PutBank(int id, Bank bank)
        {
            if (id != bank.BankId)
            {
                return(BadRequest());
            }

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

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

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

            if (id != klinik.KlinikID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #4
0
        public async Task <ServiceResponse <string> > Upload(FileDto file)
        {
            ServiceResponse <string> response = new ServiceResponse <string>();

            if (await FileExist(file.FileName))
            {
                response.Success = false;
                response.Message = "File with the same name already exists.";
                return(response);
            }

            if (!FileCategoryExist(file.Category))
            {
                response.Success = false;
                response.Message = "Category does not exist.";
                return(response);
            }

            UploadedFile uploadableFile = new UploadedFile()
            {
                Category = (FileCategory)Enum.Parse(typeof(FileCategory), file.Category, true),
                Date     = DateTime.Now,
                //FileAsByteArray = UnescapeText(file.FileAsByteArray),
                FileAsByteArray = StringToByteArray(file.FileAsString),
                FileName        = file.FileName.ToLower()
            };

            await _context.UploadedFiles.AddAsync(uploadableFile);

            await _context.SaveChangesAsync();

            response.Data = file.FileName;
            return(response);
        }
コード例 #5
0
        public async Task <IActionResult> PutBankAccount([FromRoute] int id, [FromBody] BankAccount bankAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bankAccount.BankAccountID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #6
0
        public async Task <IActionResult> PutCliente(int id, Cliente cliente)
        {
            if (id != cliente.clienteID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #7
0
        public async Task <IActionResult> Putattribute_value(string id, attribute_value attribute_value)
        {
            if (id != attribute_value.attribute_value_code)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #8
0
        public async Task <IActionResult> PutTeacher(int id, Teacher teacher)
        {
            if (id != teacher.TeacherID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #9
0
        public async Task <IActionResult> PutCertificationScheme(string id, CertificationScheme certificationScheme)
        {
            if (id != certificationScheme.name)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #10
0
        public async Task <IActionResult> PutItem(int id, Item item)
        {
            if (id != item.ItemID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #11
0
        public async Task <IActionResult> PutAccount(int id, Account account)
        {
            if (id != account.BankAccountID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #12
0
        public async Task <IActionResult> PutDepartments(int id, Departments departments)
        {
            if (id != departments.departmentsID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #13
0
        public async Task <ActionResult <Concert> > PostConcert([FromBody] Concert concert)
        {
            _context.Concert.Add(concert);

            await _context.SaveChangesAsync();

            return(NoContent());
        }
コード例 #14
0
ファイル: ProductService.cs プロジェクト: okirasov/pois1903v
        public async Task <bool> CreateOrUpdate(ProductDTO dto)
        {
            if (dto.ID > 0 && !IsExist(dto.ID))
            {
                return(false);
            }

            var product = new Product
            {
                Name  = dto.Name,
                Price = dto.Price
            };

            if (dto.CompanyID.HasValue)
            {
                var company = await _context.Companies.FindAsync(dto.CompanyID.Value);

                if (company != null)
                {
                    product.Company = company;
                }
            }

            ///////// orders/////
            if (dto.Orders.Any())
            {
                var orders = new List <Order>();
                foreach (OrderDTO order in dto.Orders)
                {
                    orders.Add(await _context.Orders.FindAsync(order.OrderID));
                }
                if (orders.Any())
                {
                    product.Orders = orders;
                }
            }
            /////////////////////


            if (dto.ID > 0)
            {
                _context.Entry(product).State = EntityState.Modified;
            }
            else
            {
                _context.Products.Add(product);
            }
            await _context.SaveChangesAsync();

            return(true);
        }
コード例 #15
0
ファイル: InitUsersDB.cs プロジェクト: melbegyn/GIGTickets
        public async void Initialize()
        {
            var user = new ApplicationUser
            {
                NormalizedEmail    = "*****@*****.**",
                Email              = "*****@*****.**",
                FullName           = "admin user",
                UserName           = "******",
                NormalizedUserName = "******",
                homeAddress        = "7th Malcolm AV, 90025 Los Angeles",
                EmailConfirmed     = true,
                SecurityStamp      = Guid.NewGuid().ToString("D")
            };


            if (!_context.Users.Any(u => u.UserName == user.UserName))
            {
                var password = new PasswordHasher <ApplicationUser>();
                var hashed   = password.HashPassword(user, "admin");
                user.PasswordHash = hashed;

                var userStore = new UserStore <ApplicationUser>(_context);
                var result    = userStore.CreateAsync(user);
            }

            await _context.SaveChangesAsync();
        }
コード例 #16
0
ファイル: ToDoService.cs プロジェクト: masmuh/WebApi-NetCore
        public async Task <bool> AddAsync(ToDoItem newItem)
        {
            var entity = new ToDoItem
            {
                Id          = Guid.NewGuid(),
                Title       = newItem.Title,
                Description = newItem.Description,
                Complete    = Convert.ToSingle(newItem.Complete),
                DueDate     = Convert.ToDateTime(newItem.DueDate)
            };

            _context.ToDoItem.Add(entity);

            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
コード例 #17
0
        public async Task PostImage(IFormFile formFile)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                foreach (var Image in files)
                {
                    if (Image != null && Image.Length > 0)
                    {
                        var file = Image;
                        //There is an error here
                        var uploads = Path.Combine(Environment.WebRootPath, "Image");
                        if (file.Length > 0)
                        {
                            var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName);
                            using (var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create))
                            {
                                await file.CopyToAsync(fileStream);

                                Image images = new Image()
                                {
                                    ImageCaption = "Upload",
                                    ImageName    = fileName
                                };
                                _context.Add(images);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }
            //return CreatedAtAction("GetImage", new { id = image.ImageID }, image);
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            //string path = Path.Combine(this.Environment.WebRootPath, "Uploads");
            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            ////Save to DB
            //Image images = new Image()
            //{
            //    ImageCaption = image.ImageCaption,
            //    ImageName = image.ImageName
            //};

            //_context.Images.Add(image);
            //await _context.SaveChangesAsync();

            //return CreatedAtAction("GetImage", new { id = image.ImageID }, image);
        }
コード例 #18
0
        public async Task <bool> CreateOrUpdate(CompanyDTO dto)
        {
            if (dto == null)
            {
                return(false);
            }

            var company = new Company
            {
                Name    = dto.Name,
                Address = dto.Address
            };

            _context.Companies.Add(company);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
コード例 #19
0
ファイル: UserService.cs プロジェクト: okirasov/pois1903v
        public async Task <bool> CreateOrUpdate(UserDTO dto)
        {
            // for Update request only!!!
            // check if User exists
            if (dto.ID > 0 && !IsExist(dto.ID))
            {
                return(false);
            }

            var user = new User
            {
                ID        = dto.ID,
                FirstName = dto.FirstName,
                LastName  = dto.LastName,
                Email     = dto.Email
            };

            // Load Company
            if (dto.CompanyID.HasValue)
            {
                var company = await _context.Companies.FindAsync(dto.CompanyID.Value);

                if (company != null)
                {
                    user.Company = company;
                }
            }

            // Update Request
            if (dto.ID > 0)
            {
                _context.Entry(user).State = EntityState.Modified;
            }
            // Insert Request
            else
            {
                _context.Users.Add(user);
            }

            await _context.SaveChangesAsync();

            return(true);
        }
コード例 #20
0
        //POST :/Proyecto/
        public async Task <ActionResult <ProyectoDTO> > PostProyecto(ProyectoDTO proyectoDTO)
        {
            var proyecto = _mapper.Map <Proyecto>(proyectoDTO);

            proyecto.IsDeleted = false;

            //Control: fecha de inicio debe ser menor que fecha de finalizacion
            var result = System.DateTime.Compare(proyecto.FechaInicio, proyecto.FechaFinalizacion);

            if (result > 0)
            {
                return(BadRequest(new { message = "La fecha de inicio debe ser anterior a su finalizacion" }));
            }

            _context.Proyectos.Add(proyecto);

            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #21
0
        public async Task <bool> CreateOrUpdate(OrderDTO dto)
        {
            if (dto.ID > 0 && !IsExist(dto.ID))
            {
                return(false);
            }

            var order = new Order
            {
                OrderID    = dto.OrderID,
                CreateDate = dto.CreateDate,
                ShipDate   = dto.ShipDate,
                Price      = dto.Price
            };

            if (dto.ProductID.HasValue)
            {
                var product = await _context.Products.FindAsync(dto.ProductID.Value);

                if (product != null)
                {
                    order.Product = product;
                }
            }

            if (dto.ID > 0)
            {
                _context.Entry(order).State = EntityState.Modified;
            }
            else
            {
                _context.Orders.Add(order);
            }
            await _context.SaveChangesAsync();

            return(true);
        }
コード例 #22
0
        //POST :/Hora/
        public async Task <ActionResult <HoraDTO> > PostHora(HoraDTO horaDTO)
        {
            var hora = _mapper.Map <Hora>(horaDTO);

            if (hora.Cantidad <= 0 || hora.Cantidad > 24)
            {
                return(BadRequest(new { message = "La cantidad de horas debe ser mayor a cero y menor a 24" }));
            }

            if (hora.Dia == null)
            {
                return(BadRequest(new { message = "Debe especificar la fecha" }));
            }

            _context.Horas.Add(hora);

            await _context.SaveChangesAsync();

            return(Ok());
        }
コード例 #23
0
        public async Task <ServiceResponse <int> > Register(User user, string password)
        {
            ServiceResponse <int> response = new ServiceResponse <int>();

            if (await UserExists(user.Name))
            {
                response.Success = false;
                response.Message = "User already exists.";
                return(response);
            }
            CreatePasswordHash(password, out byte[] passwordHash, out byte[] passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            response.Data = user.UserId;
            return(response);
        }