Пример #1
0
        public async Task <IActionResult> PutDetectionResult(Guid id, DetectionResult detectionResult)
        {
            if (id != detectionResult.DetectionResultId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutJob(Guid id, Job job)
        {
            if (id != job.JobId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #3
0
        public async Task <IHttpActionResult> PutHistory(int id, History history)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #4
0
        public async Task <IHttpActionResult> PutPaymentType(int id, PaymentType paymentType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != paymentType.PaymentTypeId)
            {
                return(BadRequest());
            }

            _applicationDatabaseContext.Entry(paymentType).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #5
0
        public async Task <IActionResult> UpdateRegion([FromBody] RegionDto regionDto)
        {
            _log.LogDebug($"REST request to update Region : {regionDto}");
            if (regionDto.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }

            //TODO catch //DbUpdateConcurrencyException into problem

            Region region = _mapper.Map <Region>(regionDto);

            region.UserId = region.User.Id;
            region.User   = null;
            _applicationDatabaseContext.Update(region);

            /* Force the reference navigation property to be in "modified" state.
             * This allows to modify it with a null value (the field is nullable).
             * This takes into consideration the case of removing the association between the two instances. */
            _applicationDatabaseContext.Entry(region).Reference(region0 => region0.User).IsModified = true;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(region)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, region.Id.ToString())));
        }
Пример #6
0
 public void Update(Product product)
 {
     using (var context = new ApplicationDatabaseContext())
     {
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #7
0
 public void Delete(WishList wishList)
 {
     using (var context = new ApplicationDatabaseContext())
     {
         context.Entry(wishList).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Пример #8
0
        public async Task <IActionResult> UpdateEmployee([FromBody] Employee employee)
        {
            _log.LogDebug($"REST request to update Employee : {employee}");
            if (employee.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Update(employee);

            /* Force the reference navigation property to be in "modified" state.
             * This allows to modify it with a null value (the field is nullable).
             * This takes into consideration the case of removing the association between the two instances. */
            _applicationDatabaseContext.Entry(employee).Reference(employee0 => employee0.Manager).IsModified    = true;
            _applicationDatabaseContext.Entry(employee).Reference(employee0 => employee0.Department).IsModified = true;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(employee)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, employee.Id.ToString())));
        }
Пример #9
0
        public async Task <IActionResult> Edit(string id, [FromForm] Event model)
        {
            if (id != model.Id)
            {
                return(BadRequest());
            }

            var exist = await _context.Events.Where(e => e.Name.Equals(model.Name)).FirstOrDefaultAsync();

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

                _context.Entry(exist).State = EntityState.Detached;
            }



            var entity = await _context.Events.FindAsync(id);

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

            entity.Name                  = model.Name;
            entity.Description           = model.Description;
            _context.Entry(entity).State = EntityState.Modified;

            bool result = Convert.ToBoolean(await _context.SaveChangesAsync());

            if (result)
            {
                return(Ok(entity));
            }

            return(BadRequest());
        }
Пример #10
0
        public async Task <IActionResult> EditCategory(string tagId, [FromForm] Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (tagId != tag.Id)
            {
                return(BadRequest());
            }

            var existTag = await _context.Tags.Where(c => c.Name.Equals(tag.Name)).FirstOrDefaultAsync();

            if (existTag != null && tag.Id != existTag.Id)
            {
                return(BadRequest());
            }

            if (existTag != null)
            {
                _context.Entry(existTag).State = EntityState.Detached;
            }

            var model = await _context.Tags.FindAsync(tagId);

            if (model == null)
            {
                return(BadRequest());
            }

            model.Name = tag.Name;
            _context.Entry(model).State = EntityState.Modified;

            if (await Save())
            {
                return(Ok(model));
            }

            return(BadRequest());
        } // end
Пример #11
0
        public async Task <IActionResult> EditCategory(string categoryId, [FromForm] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (categoryId != category.Id)
            {
                return(BadRequest());
            }

            var existCategory = await _context.Categories.Where(c => c.Name.Equals(category.Name)).FirstOrDefaultAsync();

            if (existCategory != null && category.Id != existCategory.Id)
            {
                return(BadRequest());
            }

            if (existCategory != null)
            {
                _context.Entry(existCategory).State = EntityState.Detached;
            }

            var model = await _context.Categories.FindAsync(categoryId);

            if (model == null)
            {
                return(BadRequest());
            }

            model.Name = category.Name;
            _context.Entry(model).State = EntityState.Modified;

            if (await Save())
            {
                return(Ok(model));
            }

            return(BadRequest());
        } // end
Пример #12
0
        public AddMemberResponse Update(Attendance attend)
        {
            AddMemberResponse response = new AddMemberResponse();

            //Attendance member = JsonConvert.DeserializeObject<Attendance>(memberData);
            if (!MemberExists(attend.MemberId))
            {
                response.Status   = false;
                response.Message  = "Member does not exist.";
                response.MemberId = -1;
                return(response);
            }
            if (attend.Status != null)
            {
                _context.Entry(attend).Property(x => x.Status).IsModified = true;
            }
            else if (attend.MemberId != null)
            {
                _context.Entry(attend).Property(x => x.MemberId).IsModified = true;
            }
            else if (attend.EventDate != null)
            {
                _context.Entry(attend).Property(x => x.EventDate).IsModified = true;
            }
            try
            {
                _context.SaveChanges();
                response.Status   = true;
                response.Message  = "Updated successfully.";
                response.MemberId = attend.MemberId;
                return(response);
            }
            catch (DbUpdateConcurrencyException) {
                response.Status   = false;
                response.Message  = "Update failed.";
                response.MemberId = -1;
                return(response);
            }
        }
        public async Task <IActionResult> UpdateOperation([FromBody] Operation operation)
        {
            _log.LogDebug($"REST request to update Operation : {operation}");
            if (operation.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Entry(operation).State = EntityState.Modified;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(operation).WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, operation.Id.ToString())));
        }
Пример #14
0
        public async Task <IActionResult> UpdateLabel([FromBody] Label label)
        {
            _log.LogDebug($"REST request to update Label : {label}");
            if (label.Id == null)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.Entry(label).State = EntityState.Modified;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(label)
                   .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, label.Id)));
        }
Пример #15
0
        public User EditUser(User user)
        {
            if (!UserExists(user.Id))
            {
                user.Message = "Sorry, user not found.";
                return(user);
            }
            if (user.Password != null)
            {
                _context.Entry(user).Property(x => x.Password).IsModified = true;
            }
            if (user.Status != null)
            {
                _context.Entry(user).Property(x => x.Status).IsModified = true;
            }
            if (user.Role != null)
            {
                _context.Entry(user).Property(x => x.Role).IsModified = true;
            }
            if (user.Surname != null)
            {
                _context.Entry(user).Property(x => x.Surname).IsModified = true;
            }
            if (user.FirstName != null)
            {
                _context.Entry(user).Property(x => x.FirstName).IsModified = true;
            }
            if (user.Email != null)
            {
                _context.Entry(user).Property(x => x.Email).IsModified = true;
            }

            try
            {
                _context.SaveChanges();
                user.Message = "User updated successfully.";
                return(user);
            }
            catch (DbUpdateConcurrencyException e)
            {
                if (!UserExists(user.Id))
                {
                    user.Message = "User update failed. Exception: " + e.ToString();
                }
                else
                {
                    throw;
                }
            }
            return(user);
        }
Пример #16
0
        public async Task <IActionResult> UpdateOperation([FromBody] Operation operation)
        {
            _log.LogDebug($"REST request to update Operation : {operation}");
            if (operation.Id == 0)
            {
                throw new BadRequestAlertException("Invalid Id", EntityName, "idnull");
            }
            //TODO catch //DbUpdateConcurrencyException into problem
            _applicationDatabaseContext.OperationLabels.RemoveNavigationProperty(operation, operation.Id);
            _applicationDatabaseContext.Update(operation);

            /* Force the reference navigation property to be in "modified" state.
             * This allows to modify it with a null value (the field is nullable).
             * This takes into consideration the case of removing the association between the two instances. */
            _applicationDatabaseContext.Entry(operation).Reference(o => o.BankAccount).IsModified = true;
            await _applicationDatabaseContext.SaveChangesAsync();

            return(Ok(operation).WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, operation.Id.ToString())));
        }
Пример #17
0
        public async Task <IActionResult> UpdateProfileInfo([FromForm] UpdateProfileInfoViewModel model)
        {
            var user = await _userService.CurrentUser();

            var profile = await _context.Profiles.Where(u => u.AccountId.Equals(user.Id)).FirstOrDefaultAsync();

            profile.FirstName   = model.FirstName;
            profile.LastName    = model.LastName;
            profile.FatherName  = model.FatherName;
            profile.CodeMeli    = model.CodeMeli;
            profile.Description = model.Description;

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

            bool result = Convert.ToBoolean(await _context.SaveChangesAsync());

            if (result)
            {
                return(Ok(profile));
            }

            return(BadRequest());
        }
Пример #18
0
 public void Update(TEntity obj)
 {
     _dbContext.Entry(obj).State = EntityState.Modified;
 }
Пример #19
0
        public async Task <IActionResult> PutMember(int id, MemberRequest member)
        {
            if (id != member.Id)
            {
                return(BadRequest());
            }

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

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