Пример #1
0
        public async Task <IHttpActionResult> Get(string contractId)
        {
            try
            {
                var lstSearch = MemoryInfo.GetListContractByField(contractId, Contract.ContractFields.ContractId);
                var data      = lstSearch[0];
                if (data != null && data.IsDeleted == 1)
                {
                    data = null;
                }
                var res = new RequestErrorCode(true, null, null);
                if (data != null && data.IsDeleted == 1)
                {
                    res.DataResult = null;
                    return(Ok(res));
                }

                if (data != null)
                {
                    var lstPayment =
                        MemoryInfo.GetListPaymentByField(data.Id.ToString(), Payment.PaymentFields.IdContract);
                    var         customer = MemoryInfo.GetCustomer(data.IdCustomer);
                    ContractRes result   = new ContractRes(data, customer, lstPayment);
                    res.DataResult = result;
                    return(Ok(res));
                }
                res.DataResult = data;
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Пример #2
0
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         var lstData = MemoryInfo.GetAllContract();
         List <ContractRes> lstResult = new List <ContractRes>();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         var lstPayment = MemoryInfo.GetAllPayment();
         foreach (var item in lstData)
         {
             List <Payment> payments = new List <Payment>();
             payments = lstPayment.Where(x => x.IdContract == item.Id).ToList();
             var         customer = MemoryInfo.GetCustomer(item.IdCustomer);
             ContractRes temp     = new ContractRes(item, customer, payments);
             lstResult.Add(temp);
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         var data = MemoryInfo.GetCustomer(id);
         if (data != null && data.IsDeleted == 1)
         {
             data = null;
         }
         var res = new RequestErrorCode(true, null, null);
         res.DataResult = data;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
Пример #4
0
        public async Task <IHttpActionResult> Get(int id)
        {
            try
            {
                #region token
                var header = Request.Headers;
                if (header.Authorization == null)
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                var      token = header.Authorization.Parameter;
                Employee employee;
                if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                #endregion
                var data = MemoryInfo.GetCustomerFeedback(id);
                var res  = new RequestErrorCode(true, null, null);
                if (data != null && data.IsDeleted == 1)
                {
                    res.DataResult = null;
                    return(Ok(res));
                }

                if (data != null)
                {
                    var customer = MemoryInfo.GetCustomer(data.IdCustomer);
                    CustomerFeedbackRes result = new CustomerFeedbackRes(data, customer);
                    res.DataResult = result;
                    return(Ok(res));
                }
                res.DataResult = data;
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Пример #5
0
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         #region token
         var header = Request.Headers;
         if (header.Authorization == null)
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         var      token = header.Authorization.Parameter;
         Employee employee;
         if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         #endregion
         List <CustomerFeedbackRes> lstResult = new List <CustomerFeedbackRes>();
         var lstData = MemoryInfo.GetAllCustomerFeedback();
         if (lstData != null)
         {
             lstData = lstData.Where(x => x.IsDeleted != null && x.IsDeleted != 1).ToList();
         }
         foreach (var item in lstData)
         {
             var customer             = MemoryInfo.GetCustomer(item.IdCustomer);
             CustomerFeedbackRes temp = new CustomerFeedbackRes(item, customer);
             lstResult.Add(temp);
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
        public async Task <IHttpActionResult> Delete(int id)
        {
            try
            {
                string errorMessage = "UnknowError";
                string errorCode    = ErrorCodeEnum.UnknownError.ToString();
                #region token
                var header = Request.Headers;
                if (header.Authorization == null)
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                var      token = header.Authorization.Parameter;
                Employee employee;
                if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                #endregion
                if (!Operator.IsAdmin(employee))
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_NotHavePermision.ToString(), "Khong co quyen")));
                }

                #region Check exist
                var obj = MemoryInfo.GetCustomer(id);
                if (obj == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                #endregion

                bool isHasDeleteProperties = obj.GetType().GetProperty("IsDeleted") != null;
                if (!isHasDeleteProperties)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                obj.IsDeleted = 1;

                #region Process
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(obj), EntityAction = EntityAction.Update
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(obj);
                var result = new RequestErrorCode(true);
                result.DataResult = obj;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }