public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         var             data    = MemoryInfo.GetServicePack(id);
         ServicesPackRes itemRes = null;
         if (data != null)
         {
             if (data.IsDeleted != 1)
             {
                 string cnTypeName  = "";
                 var    connectType = MemoryInfo.GetConnectionType(data.IdConnectionType);
                 if (connectType != null)
                 {
                     cnTypeName = connectType.Name;
                 }
                 var lstSvPackFee = MemoryInfo.GetListServicePackFeeByField(data.Id.ToString(),
                                                                            ServicePackFee.ServicePackFeeFields.IdServicePack);
                 itemRes = new ServicesPackRes(data, cnTypeName, lstSvPackFee);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.DataResult = itemRes;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
        public async Task <IHttpActionResult> Get()
        {
            try
            {
                List <ServicesPackRes> lstResult = new List <ServicesPackRes>();
                var lstData = MemoryInfo.GetAllServicePack();
                foreach (var servicePack in lstData)
                {
                    if (servicePack.IsDeleted != 1)
                    {
                        string cnTypeName  = "";
                        var    connectType = MemoryInfo.GetConnectionType(servicePack.IdConnectionType);
                        if (connectType != null)
                        {
                            cnTypeName = connectType.Name;
                        }

                        var lstSvPackFee = MemoryInfo.GetListServicePackFeeByField(servicePack.Id.ToString(),
                                                                                   ServicePackFee.ServicePackFeeFields.IdServicePack);
                        ServicesPackRes itemRes = new ServicesPackRes(servicePack, cnTypeName, lstSvPackFee);
                        lstResult.Add(itemRes);
                    }
                }
                var res = new RequestErrorCode(true, null, null);
                res.ListDataResult.AddRange(lstResult);
                return(Ok(res));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Пример #3
0
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         var data = MemoryInfo.GetConnectionType(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> 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.GetConnectionType(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"));
        }