Exemplo n.º 1
0
        public async Task <DatabaseResponse> UpdateQrc(UpdateQrcMaster qrcMaster, int id)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@Id",          SqlDbType.Int),
                    new SqlParameter("@Name",        SqlDbType.NVarChar),
                    new SqlParameter("@Description", SqlDbType.NVarChar),
                    new SqlParameter("@UpdatedBy",   SqlDbType.Int),
                    new SqlParameter("@Active",      SqlDbType.Bit),
                    new SqlParameter("@CategoryIds", SqlDbType.NVarChar)
                };


                parameters[0].Value = id;
                parameters[1].Value = qrcMaster.Name;
                parameters[2].Value = qrcMaster.Description;
                parameters[3].Value = qrcMaster.UpdatedBy;
                parameters[4].Value = qrcMaster.Active;
                parameters[5].Value = qrcMaster.CategoryIds;
                _DataHelper         = new DataAccessHelper("UpdateQrc", parameters, _configuration);

                DataTable dt = new DataTable();

                int result = await _DataHelper.RunAsync(dt);

                List <QrcMaster> qrcs = new List <QrcMaster>();

                if (dt != null && dt.Rows.Count > 0)
                {
                    qrcs = (from model in dt.AsEnumerable()
                            select new QrcMaster()
                    {
                        Id = model.Field <int>("Id"),
                        Name = model.Field <string>("Name"),
                        Description = model.Field <string>("Description"),
                        CreatedBy = model.Field <string>("CreatedBy"),
                        CreatedOn = model.Field <DateTime>("CreatedOn"),
                        UpdatedOn = model.Field <DateTime>("UpdatedOn"),
                        UpdatedBy = model.Field <string>("UpdatedBy"),
                        Active = model.Field <bool>("Active")
                    }).ToList();
                }

                return(new DatabaseResponse {
                    ResponseCode = result, Results = qrcs
                });
            }

            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                throw;
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put(int id, [FromBody] UpdateQrcMaster qrc)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        StatusCode = ((int)ResponseStatus.BadRequest).ToString(),
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    }));
                }

                QrcDataAccess _qrcAccess = new QrcDataAccess(_iconfiguration, _converter);

                DatabaseResponse response = await _qrcAccess.UpdateQrc(qrc, id);

                if (response.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.NotExists),
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }