public async Task <IOperationResult <bool> > Update(PermitCreateOrEditViewModel permitToUpdate)
        {
            try
            {
                IOperationResult <string> validationResult = ValidatePermit(permitToUpdate);

                if (!validationResult.Success)
                {
                    return(OperationResult <bool> .Fail(validationResult.Message));
                }

                Permit permit = await _permitRepositoy.FindAsync(permit => permit.Id == permitToUpdate.Id);

                PermitType permitType = await _permitTypeRepository.FindAsync(permitType => permitType.Id == permitToUpdate.PermitType);

                if (permitType == null)
                {
                    return(OperationResult <bool> .Fail("No se encontro el permiso en la base de datos."));
                }

                permit.EmployeeName     = permitToUpdate.EmployeeName;
                permit.EmployeeLastName = permitToUpdate.EmployeeLastName;
                permit.PermitType       = permitType;
                permit.Date             = permitToUpdate.Date;

                await _permitRepositoy.SaveAsync();

                return(OperationResult <bool> .Ok(true));
            }
            catch
            {
                return(OperationResult <bool> .Fail("Ha ocurrido un error al actualizar el permiso."));
            }
        }
        private PermitTypeViewModel BuildPermitType(int permitTypeId)
        {
            PermitType permitType = _permitTypeRepository.Find(permitType => permitType.Id == permitTypeId);

            return(new PermitTypeViewModel
            {
                Id = permitType.Id,
                Description = permitType.Description
            });
        }
Beispiel #3
0
        /// <summary>
        /// 获取枚举描述
        /// </summary>
        /// <param name="e">枚举类别</param>
        /// <returns>枚举描述</returns>
        public static String GetEnumDesc(PermitType e)
        {
            FieldInfo EnumInfo = e.GetType().GetField(e.ToString());

            DescriptionAttribute[] EnumAttributes = (DescriptionAttribute[])EnumInfo.
                                                    GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (EnumAttributes.Length > 0)
            {
                return(EnumAttributes[0].Description);
            }
            return(e.ToString());
        }
        private async Task <PermitViewModel> BuildPermit(Permit permit)
        {
            PermitType permitType = await _permitTypeRepository.FindAsync(permitType => permitType.Id == permit.PermitType.Id);

            return(new PermitViewModel
            {
                Id = permit.Id,
                EmployeeName = permit.EmployeeName,
                EmployeeLastName = permit.EmployeeLastName,
                PermitType = BuildPermitType(permit.PermitType.Id),
                Date = permit.Date.ToString("yyyy-MM-dd")
            });
        }
Beispiel #5
0
        public async Task <ActionResult> Post(PermitType entity)
        {
            try
            {
                await _service.Create(entity);

                await _service.SaveChanges();
            }
            catch (Exception)
            {
                return(BadRequest(new { entity = entity, message = "There was a problem adding the PermitType" }));
            }

            return(Created("/permitType", entity));
        }
        private async Task <IOperationResult <Permit> > BuildPermit(PermitCreateOrEditViewModel permitToCreate)
        {
            PermitType permitType = await _permitTypeRepository.FindAsync(permitType => permitType.Id == permitToCreate.PermitType);

            if (permitType == null)
            {
                return(OperationResult <Permit> .Fail("No se encontro el permiso en la base de datos."));
            }

            var permit = new Permit
            {
                Id               = 0,
                EmployeeName     = permitToCreate.EmployeeName,
                EmployeeLastName = permitToCreate.EmployeeLastName,
                PermitType       = permitType,
                Date             = permitToCreate.Date
            };

            return(OperationResult <Permit> .Ok(permit));
        }
Beispiel #7
0
        public async Task <ActionResult> Put(int id, PermitType entity)
        {
            // Validate that the params are from the same entity to avoid injection attacks.  TLDR;
            if (id != entity.Id)
            {
                return(BadRequest());
            }

            try
            {
                _service.Update(entity);
                await _service.SaveChanges();
            }
            catch (Exception)
            {
                return(BadRequest(new { entity = entity, message = "There was a problem updating the Permit Type" }));
            }

            return(NoContent());
        }
Beispiel #8
0
 public void Remove(PermitType entity)
 {
     _repository.Remove(entity);
 }
Beispiel #9
0
 public void Update(PermitType entity)
 {
     _repository.Update(entity);
 }
Beispiel #10
0
 public async Task Create(PermitType entity)
 {
     await _repository.Create(entity);
 }
Beispiel #11
0
        public PermitType CreateNewPermitType(PermitType permitType)
        {
            var result = _permitRepository.CreatePermitType(permitType);

            return(result);
        }
Beispiel #12
0
        public PermitType CreatePermitType(PermitType permitType)
        {
            var result = _context.PermitTypes.Add(permitType);

            return(result.Entity);
        }