Exemplo n.º 1
0
        public async Task <IHttpActionResult> PostAPIIntegrationMaster(APIIntegrationDTO data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Guid id            = data.Id;
            int  EntityStateId = 0;

            if (id == Guid.Empty)
            {
                id = Guid.NewGuid();
                //user.Id = id;
                EntityStateId = (int)EntityState.Added;
            }
            else
            {
                EntityStateId = (int)EntityState.Modified;
            }

            Guid result = await _APIIntegrationService.Save(data, id, EntityStateId);

            data.Id = id;
            if (result == Guid.Empty)
            {
                return(NotFound());
            }

            return(CreatedAtRoute("DefaultApi", new { id = id }, data));
        }
Exemplo n.º 2
0
        public IQueryable <APIIntegrationDTO> GetAll()
        {
            db = new DatabaseEntities();
            var data = db.APIIntegrations.Select(o => new APIIntegrationDTO
            {
                Id         = o.Id,
                Name       = o.Name,
                URL        = o.URL,
                UserName   = o.UserName,
                Password   = o.Password, //o.Password,
                StatusCode = o.StatusCode
            }).DefaultIfEmpty();

            List <APIIntegrationDTO> APIIntegrationDTOs = new List <APIIntegrationDTO>();

            foreach (APIIntegrationDTO API in data)
            {
                APIIntegrationDTO APIInteg = new APIIntegrationDTO();
                APIInteg.Id         = API.Id;
                APIInteg.Id         = API.Id;
                APIInteg.Name       = API.Name;
                APIInteg.URL        = API.URL;
                APIInteg.UserName   = API.UserName;
                APIInteg.Password   = PasswordManager.DecryptText(API.Password); //o.Password,
                APIInteg.StatusCode = API.StatusCode;
                APIIntegrationDTOs.Add(APIInteg);
            }

            return(APIIntegrationDTOs.AsQueryable());
        }
Exemplo n.º 3
0
        public async Task <Guid> Save(APIIntegrationDTO _Dto, Guid Id, int EntityState)
        {
            APIIntegration _APIIntegration = new APIIntegration();

            if (_Dto != null)
            {
                _APIIntegration.Id         = Id;
                _APIIntegration.Name       = _Dto.Name;
                _APIIntegration.URL        = _Dto.URL;
                _APIIntegration.UserName   = _Dto.UserName;
                _APIIntegration.Password   = PasswordManager.DecryptText(_Dto.Password);
                _APIIntegration.StatusCode = EMPConstants.Active;
            }

            if (_Dto.Id != null)
            {
                _APIIntegration.CreatedBy       = _Dto.UserId;
                _APIIntegration.CreatedDate     = DateTime.Now;
                _APIIntegration.LastUpdatedBy   = _Dto.UserId;
                _APIIntegration.LastUpdatedDate = DateTime.Now;
            }
            else
            {
                _APIIntegration.LastUpdatedBy   = _Dto.UserId;
                _APIIntegration.LastUpdatedDate = DateTime.Now;
            }

            if (EntityState == (int)System.Data.Entity.EntityState.Modified)
            {
                db.Entry(_APIIntegration).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                db.APIIntegrations.Add(_APIIntegration);
            }

            try
            {
                await db.SaveChangesAsync();

                return(_APIIntegration.Id);
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!IsExists(_APIIntegration.Id))
                {
                    return(_APIIntegration.Id);
                }
                else
                {
                    throw;
                }
            }
        }