Example #1
0
        public ResponseResult UpdateTrangThai(ChungTuModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var result = new Response<LoaiChungTuModel>
                    {
                        Message = HttpMessage.INVALID_MODEL,
                        Status = false,
                    };
                    ActionContext.Response.StatusCode = HttpStatusCode.BadRequest;
                    return new ResponseResult(result, ActionContext);
                }

                var ct = _chungtuService.GetEntityById(model.Id);
                // check exist
                if (ct == null)
                {
                    var result = new Response<ChungTuModel>
                    {
                        Message = HttpMessage.DATA_NOT_FOUND,
                        Status = false,
                    };
                    ActionContext.Response.StatusCode = HttpStatusCode.NotFound;
                    return new ResponseResult(result, ActionContext);
                }
                ct.TrangThai = model.TrangThai;
                _chungtuService.Update(ct);
                var data = new Response<ChungTuModel>
                {
                    Message = "Edit Success",
                    Status = true,
                    Data = model
                };

                return new ResponseResult(data, ActionContext);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                var data = new Response<ChungTuModel>
                {
                    Message = HttpMessage.ERROR_EDIT,
                    Status = false
                };
                ActionContext.Response.StatusCode = HttpStatusCode.InternalServerError;
                return new ResponseResult(data, ActionContext);
            }
        }
Example #2
0
        public ResponseResult Signature(ChungTuModel model)
        {
            try
            {
                string domain;
                var folderPath = "";
                var fileName = "";
                var myuri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
                var pathQuery = myuri.PathAndQuery;
                var appUrl = HttpRuntime.AppDomainAppVirtualPath;
                domain = myuri.ToString().Replace(pathQuery, "") + appUrl.Trim();
                string currentDir = HttpContext.Current.Server.MapPath("~");
                if (!ModelState.IsValid)
                {
                    var result = new Response<LoaiChungTuModel>
                    {
                        Message = HttpMessage.INVALID_MODEL,
                        Status = false,
                    };
                    ActionContext.Response.StatusCode = HttpStatusCode.BadRequest;
                    return new ResponseResult(result, ActionContext);
                }

                var ct = _chungtuService.GetEntityById(model.Id);
                // check exist
                if (ct == null)
                {
                    var result = new Response<ChungTuModel>
                    {
                        Message = HttpMessage.DATA_NOT_FOUND,
                        Status = false,
                    };
                    ActionContext.Response.StatusCode = HttpStatusCode.NotFound;
                    return new ResponseResult(result, ActionContext);
                }
                // Create new barcode and register it.
                Bytescout.BarCode.Barcode barcode = new Bytescout.BarCode.Barcode();
                barcode.RegistrationName = "demo";
                barcode.RegistrationKey = "demo";

                // Set symbology
                barcode.Symbology = SymbologyType.Code93;
                // Set value
                barcode.Value = model.Id.ToString();
                // Place barcode at bottom-right corner of every document page
                folderPath = @"/Uploads/" + model.Id.ToString().Trim();
                fileName = "CTResult_" + model.Id + ".pdf";
                var inputFile = currentDir + ct.FileDinhKem.Replace("~/","");
                var outPutFile = currentDir+ folderPath + "/" + fileName;
                barcode.DrawToPDF(inputFile, -1, 150, 130, outPutFile);
                ct.TrangThai = model.TrangThai;
                ct.MaVach =  model.Id.ToString();
                ct.FileDinhKem ="~"+ folderPath +"/"+ fileName;
                _chungtuService.Update(ct);
                model.FileDinhKem = domain + ct.FileDinhKem.Replace("~/", "");
                var data = new Response<ChungTuModel>
                {
                    Message = "Sign Success",
                    Status = true,
                    Data = model
                };

                return new ResponseResult(data, ActionContext);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                var data = new Response<ChungTuModel>
                {
                    Message = HttpMessage.ERROR_EDIT,
                    Status = false
                };
                ActionContext.Response.StatusCode = HttpStatusCode.InternalServerError;
                return new ResponseResult(data, ActionContext);
            }
        }