public async Task <IHttpActionResult> Post([FromBody] DetailImportReceipt req)
        {
            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 Validate
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion



                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = employee.Id;
                req.IsDeleted = 0;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req);
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 2
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

                #region Check exist
                var obj = MemoryInfo.GetEmployee(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"));
        }
Exemplo n.º 3
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

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

                // check role
                if (!Operator.IsAdmin(employee))
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_NotHavePermision.ToString(), "Khong co quyen xoa")));
                }

                #region Process
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity(obj), EntityAction = EntityAction.Delete
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                var result = new RequestErrorCode(true);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Post([FromBody] CustomerFeedback req)
        {
            try
            {
                string errorMessage = "UnknowError";
                string errorCode    = ErrorCodeEnum.UnknownError.ToString();


                #region Validate
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion

                #region Tạo key
                var oldKey = Memory.Memory.GetMaxKey(req.GetName());
                int newKey = oldKey + 1;
                // set key
                req.Id = newKey;
                #endregion

                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = 0;
                req.IsDeleted = 0;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req);
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> Post()
        {
            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

                #region Tạo key
                var oldKey = Memory.GetMaxKey(Image.EntityName());
                int newKey = oldKey + 1;
                #endregion


                #region Luu vao forlder resource
                var httpRequest = HttpContext.Current.Request;
                Dictionary <HttpPostedFile, string> dicUpload = new Dictionary <HttpPostedFile, string>();
                foreach (string file in httpRequest.Files)
                {
                    var postedFile = httpRequest.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        int MaxContentLength = 1024 * 1024 * 1; //Size = 1 MB

                        IList <string> AllowedFileExtensions = new List <string> {
                            ".jpg", ".png"
                        };
                        var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                        var extension = ext.ToLower();
                        if (!AllowedFileExtensions.Contains(extension))
                        {
                            var message = string.Format("Please Upload image of type .jpg,.png.");
                            return(Ok(new RequestErrorCode(false, errorCode, message)));
                        }
                        else if (postedFile.ContentLength > MaxContentLength)
                        {
                            var message = string.Format("Please Upload a file upto 1 mb.");
                            return(Ok(new RequestErrorCode(false, errorCode, message)));
                        }
                        else
                        {
                            dicUpload[postedFile] = PasswordGenerator.GetRandomString(12, true) + extension;
                        }
                    }
                }
                #endregion

                #region Process
                var          lstCommand  = new List <EntityCommand>();
                List <Image> lstResponse = new List <Image>();
                foreach (var temp in dicUpload)
                {
                    var filePath   = AppGlobal.NexusConfig.FolderSaveImages + "/" + temp.Value;
                    var filePosted = temp.Key;
                    filePosted.SaveAs(filePath);
                    var data = new Image
                    {
                        CreatedAt = DateTime.Now,
                        CreatedBy = employee.Id,
                        Id        = newKey,
                        Url       = temp.Value
                    };
                    lstCommand.Add(new EntityCommand {
                        BaseEntity = new Entity(data), EntityAction = EntityAction.Insert
                    });
                    // update memory
                    MemorySet.UpdateAndInsertEntity(data);

                    // gan lai response tra ve cho client
                    var objRes = data.Clone() as Image;
                    objRes.Url = AppGlobal.NexusConfig.BaseUrl + temp.Value;
                    lstResponse.Add(objRes);
                    newKey++;
                }
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();


                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                var result = new RequestErrorCode(true);
                result.ListDataResult.AddRange(lstResponse);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
        public async Task <IHttpActionResult> Put(int id, [FromBody] PaymentReq req)
        {
            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")));
                }

                var entityData = req.GetEntity();
                #region Validate
                if (!ValidateUpdate(entityData, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion

                #region Check exist
                var obj = MemoryInfo.GetPayment(id);
                if (obj == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                #endregion
                req.Id = obj.Id;                 // gan lai id de update
                #region Process
                req.UpdatedAt = DateTime.Now;
                req.UpdatedBy = employee.Id;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req.GetEntity()), EntityAction = EntityAction.Update
                });
                var isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req.GetEntity());
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> Post([FromBody] Employee req)
        {
            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));
                }

                if (employee == null || employee.Role != RoleDefinitionEnum.admin.ToString())
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_NotHavePermision.ToString(), "Khong co quyen tao user")));
                }
                #endregion

                #region Validate
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion

                #region Tạo key
                var oldKey = Memory.Memory.GetMaxKey(req.GetName());
                int newKey = oldKey + 1;
                // set key
                req.Id = newKey;
                #endregion

                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = employee.Id;
                req.IsDeleted = 0;
                req.Password  = PasswordGenerator.EncodePassword(req.Password);
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req);
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
        public async Task <IHttpActionResult> Post([FromBody] ChangePasswordReq req)
        {
            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;
                UserInfo userInfo;
                if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out userInfo))
                {
                    return(StatusCode(HttpStatusCode.Unauthorized));
                }
                // chi co admin moi co quyen tao tai khoan khac
                if (!Operator.HasPermision(userInfo.IdUserLogin, RoleDefinitionEnum.CreateUser))
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_NotHavePermision.ToString(), "Khong co quyen tao user")));
                }
                #endregion

                #region Validate
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                #region Process
                // lay ra userInfo tuong ung
                var userChange = MemoryInfo.GetListUserLoginByField(req.Username, UserLogin.UserLoginFields.Username)
                                 .FirstOrDefault();
                if (userChange == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_UserNotExist.ToString(), "Khong ton tai user")));
                }
                // check password
                var oldPassEncrypt = PasswordGenerator.EncodePassword(req.Password);
                if (userChange.Password != oldPassEncrypt)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_PasswordWrong.ToString(), "Sai password")));
                }

                var newPassEncrypt = PasswordGenerator.EncodePassword(req.NewPassword);
                userChange.Password = newPassEncrypt;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(userChange), EntityAction = EntityAction.Update
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(userChange);
                var result = new RequestErrorCode(true);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }

            Logger.Write("--------------------ErrorCodeEnum.Unknow---------------------------------");
            return(BadRequest("Unknow"));
        }
        public async Task <IHttpActionResult> Post([FromBody] ServicePackReq req)
        {
            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
                var entityData = req.GetEntity();
                #region Validate
                if (!Validate(entityData, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion

                #region Tạo key
                var oldKey = Memory.Memory.GetMaxKey(entityData.GetName());
                int newKey = oldKey + 1;
                // set key
                req.Id = newKey;
                #endregion

                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = employee.Id;
                req.IsDeleted = 0;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                if (req.ListDataTemp != null)
                {
                    foreach (var servicePackFee in req.ListDataTemp)
                    {
                        servicePackFee.IdServicePack = newKey;
                        servicePackFee.IsDeleted     = 0;
                        lstCommand.Add(new EntityCommand {
                            BaseEntity = new Entity.Entity(servicePackFee), EntityAction = EntityAction.Insert
                        });
                        MemorySet.UpdateAndInsertEntity(servicePackFee);
                    }
                }
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req.GetEntity()), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req.GetEntity());
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
        public async Task <IHttpActionResult> Put(int id, [FromBody] ServicePackReq req)
        {
            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
                var entityData = req.GetEntity();
                #region Validate
                if (!ValidateUpdate(entityData, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion

                #region Check exist
                var obj = MemoryInfo.GetServicePack(id);
                if (obj == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.DataNotExist.ToString(), "Khong ton tai")));
                }
                #endregion
                req.Id = obj.Id;                 // gan lai id de update
                #region Process
                req.UpdatedAt = DateTime.Now;
                req.UpdatedBy = employee.Id;
                UpdateEntitySql updateEntitySql  = new UpdateEntitySql();
                var             lstCommandDelete = new List <EntityCommand>();
                var             lstCommand       = new List <EntityCommand>();
                var             lstSvPackFee     = MemoryInfo.GetListServicePackFeeByField(obj.Id.ToString(), ServicePackFee.ServicePackFeeFields.IdServicePack);
                foreach (var svPackFee in lstSvPackFee)
                {
                    lstCommandDelete.Add(new EntityCommand {
                        BaseEntity = new Entity.Entity(svPackFee), EntityAction = EntityAction.Delete
                    });
                    MemorySet.RemoveMemory(svPackFee);
                }
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommandDelete);
                if (isOkDone)
                {
                    if (req.ListDataTemp != null)
                    {
                        foreach (var svPackFee in req.ListDataTemp)
                        {
                            lstCommand.Add(new EntityCommand {
                                BaseEntity = new Entity.Entity(svPackFee), EntityAction = EntityAction.Insert
                            });
                            MemorySet.UpdateAndInsertEntity(svPackFee);
                        }
                    }
                }
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req.GetEntity()), EntityAction = EntityAction.Update
                });
                isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req.GetEntity());
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> Post([FromBody] ServiceForm req)
        {
            try
            {
                string errorMessage = "UnknowError";
                string errorCode    = ErrorCodeEnum.UnknownError.ToString();

                #region Validate
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // lay connectionTypeName
                string cnTypeName = "S";
                var    svPack     =
                    MemoryInfo.GetListServicePackByField(req.IdServicePack.ToString(),
                                                         ServicePack.ServicePackFields.Id);
                if (svPack != null && svPack.Count > 0 && svPack[0] != null)
                {
                    var cnType = MemoryInfo.GetListConnectionTypeByField(svPack[0].IdConnectionType.ToString(),
                                                                         ConnectionType.ConnectionTypeFields.Id);
                    if (cnType != null && cnType.Count > 0 && cnType[0] != null)
                    {
                        cnTypeName = cnType[0].Name;
                    }
                }

                var    startStringId        = cnTypeName[0];
                var    lstSvFormWithStartId = MemoryInfo.GetListServicesFormByStartId(startStringId.ToString());
                int    idSvFormWithStartId  = lstSvFormWithStartId.Count + 1;
                string serviceFormId        = startStringId.ToString();
                int    countZeroNumber      = 10 - idSvFormWithStartId.ToString().Length;
                for (int i = 0; i < countZeroNumber; i++)
                {
                    serviceFormId += "0";
                }
                serviceFormId    += idSvFormWithStartId.ToString();
                req.ServiceFormId = serviceFormId;
                #region Tạo key
                var oldKey = Memory.Memory.GetMaxKey(req.GetName());
                int newKey = oldKey + 1;
                // set key
                req.Id = newKey;
                #endregion

                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = 0;
                req.IsDeleted = 0;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req);
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 12
0
        public async Task <IHttpActionResult> Post([FromBody] ContractReq req)
        {
            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 Validate
                if (!Validate(req.GetEntity(), out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // lay connectionTypeName
                var    startStringId          = req.ServiceFormId[0];
                var    lstContractWithStartId = MemoryInfo.GetListContractByStartId(startStringId.ToString());
                int    idContractWithStartId  = lstContractWithStartId.Count + 1;
                string contractId             = startStringId.ToString();
                int    countZeroNumber        = 15 - idContractWithStartId.ToString().Length;
                for (int i = 0; i < countZeroNumber; i++)
                {
                    contractId += "0";
                }
                contractId    += idContractWithStartId.ToString();
                req.ContractId = contractId;
                #region Tạo key
                var oldKey = Memory.Memory.GetMaxKey(req.GetEntity().GetName());
                int newKey = oldKey + 1;
                // set key
                req.Id = newKey;
                #endregion

                #region Process
                req.CreatedAt = DateTime.Now;
                req.CreatedBy = employee.Id;
                req.IsDeleted = 0;
                UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                var             lstCommand      = new List <EntityCommand>();
                lstCommand.Add(new EntityCommand {
                    BaseEntity = new Entity.Entity(req.GetEntity()), EntityAction = EntityAction.Insert
                });
                bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                if (!isOkDone)
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // update memory
                MemorySet.UpdateAndInsertEntity(req.GetEntity());
                var result = new RequestErrorCode(true);
                result.DataResult = req;
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }
            return(BadRequest("Unknow"));
        }
Exemplo n.º 13
0
        public HttpResponseMessage  Get(string req)
        {
            try
            {
                var    path = AppGlobal.GetAppPath() + AppGlobal.DEFAULT_FOLDER_CONFIG + "TemplateConfirmOrder.html";
                string Html = File.ReadAllText(path);
                if (req == null)
                {
                    Html = Html.Replace("#title", "Sorry!");
                    Html = Html.Replace("#content", "There was a problem during auto-order verification, please contact administrator for processing.");
                }
                else
                {
                    var cfOrderObj = EmailUtils.StringToConfirmOrder(req);
                    if (cfOrderObj == null)
                    {
                        Html = Html.Replace("#title", "Sorry!");
                        Html = Html.Replace("#content", "There was a problem during auto-order verification, please contact administrator for processing.");
                    }
                    else
                    {
                        var orderDetail = MemoryInfo.GetOrderDetail(cfOrderObj.OrderId);
                        if (orderDetail == null)
                        {
                            Html = Html.Replace("#title", "Sorry!");
                            Html = Html.Replace("#content", "There was a problem during auto-order verification, please contact administrator for processing.");
                        }
                        else
                        {
                            // xu li cap nhap trang thai lenh
                            orderDetail.OrderStatus = OrderStatus.Approval.ToString();
                            UpdateEntitySql updateEntitySql = new UpdateEntitySql();
                            var             lstCommand      = new List <EntityCommand>();
                            lstCommand.Add(new EntityCommand {
                                BaseEntity = new Entity.Entity(orderDetail), EntityAction = EntityAction.Update
                            });
                            bool isOkDone = updateEntitySql.UpdateDefault(lstCommand);
                            if (!isOkDone)
                            {
                                Html = Html.Replace("#title", "Sorry!");
                                Html = Html.Replace("#content", "There was a problem during auto-order verification, please contact administrator for processing.");
                            }
                            else
                            {
                                // update memory
                                MemorySet.UpdateAndInsertEntity(orderDetail);
                                Html = Html.Replace("#title", "Great!");
                                Html = Html.Replace("#content", "Confirm Order Succces!");
                            }
                        }
                    }
                }
                StringBuilder sb       = new StringBuilder(Html);
                var           response = new HttpResponseMessage();
                response.Content = new StringContent(sb.ToString());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                response.ReasonPhrase = "success";
                // what code should i write here
                return(response);
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }

            return(null);
        }