Exemple #1
0
        public async Task <HttpResponseMessage> Edit(Guid owner, Guid human, HumanIn input)
        {
            var result = new HumanEdit {
                Code = human, Human = input
            };

            return(await this.ProcessActionAsync(owner, result, this.humanService.Edit));
        }
        public IHttpActionResult Put(HumanEdit human)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = new HumanService();

            if (!service.UpdateHuman(human))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemple #3
0
        /// <summary>
        /// The edit.
        /// </summary>
        /// <param name="owner">
        /// The owner.
        /// </param>
        /// <param name="input">
        /// The input.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// The argument null exception.
        /// </exception>
        /// <exception cref="Exception">
        /// The exception.
        /// </exception>
        public async Task <bool> Edit(Guid owner, HumanEdit input)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input.Human == null)
            {
                throw new ArgumentNullException(nameof(input.Human));
            }

            if (input.Code == null)
            {
                throw new ArgumentNullException(nameof(input.Code));
            }

            //TODO: Add validations
            var ownerExits = await this.humanRepository.ExistOwner(owner);

            if (!ownerExits)
            {
                throw new Exception("User doesnt exist.");
            }

            var exitsHuman = await this.humanRepository.Exist(input.Code);

            if (!exitsHuman)
            {
                throw new Exception("User to change doesnt exist.");
            }

            var confirmIfIsOwner = await this.humanRepository.IsHeOwner(owner, input.Code);

            if (!confirmIfIsOwner)
            {
                throw new Exception("User is not owner.");
            }

            var changed = await this.humanRepository.Edit(input.Code, input.Human);

            return(changed != 0);
        }
        public bool UpdateHuman(HumanEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Humans
                    .Single(e => e.HumanID == model.HumanID);
                entity.HumanID  = model.HumanID;
                entity.FullName = model.FullName;
                entity.Address  = model.Address;
                entity.Phone    = model.Phone;
                entity.Email    = model.Email;


                return(ctx.SaveChanges() == 1);
            }
        }