public static void GenerateAndSaveQrCode(string appUserEmail, int swapId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    //var img = new TagBuilder("img");
                    //img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    //img.Attributes.Add("alt", alt);

                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(swapId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }
                    EmailHelper.EmailAttachement(appUserEmail, "QR Code", "please find the attached QR Code", path);
                }
            }
        }
Exemple #2
0
        public ActionResult ReceiveFile(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                return(BadRequest(new { Message = "fileName cannot be empty" }));
            }

            fileName = Path.GetFileNameWithoutExtension(fileName) + "-" + Guid.NewGuid() + Path.GetExtension(fileName);

            using (var fileStream = Request.Body)
            {
                if (fileStream == null)
                {
                    return(BadRequest(new { Message = "Unable to read file content" }));
                }

                var fullFileName = Path.Combine(_env.WebRootPath, Constants.CHAT_MEDIA_FOLDER_NAME, fileName);
                var done         = FileSaveHelper.Save(fullFileName, fileStream);
                if (done)
                {
                    return(Ok(new { Url = $"{Request.Scheme}://{Request.Host}/{Constants.CHAT_MEDIA_FOLDER_NAME}/{fileName}" }));
                }
                else
                {
                    return(StatusCode(500, "Unable to save received file"));
                }
            }
        }
        public static IHtmlString GenerateQrCodeForAdmin(this HtmlHelper html, int offerId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    var img = new TagBuilder("img");
                    img.Attributes.Add("src", String.Format("data:image/png;base64,{0}", Convert.ToBase64String(ms.ToArray())));
                    img.Attributes.Add("alt", Convert.ToString(offerId));

                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(offerId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }

                    return(MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing)));
                }
            }
        }
        public static string GenerateAndSaveQrCodeForOffer(string appUserEmail, int offerId, string url, string alt = "QR code", int height = 75, int width = 75, int margin = 0)
        {
            var qrWriter = new BarcodeWriter();

            qrWriter.Format  = BarcodeFormat.QR_CODE;
            qrWriter.Options = new EncodingOptions()
            {
                Height = height, Width = width, Margin = margin
            };

            using (var q = qrWriter.Write(url))
            {
                using (var ms = new MemoryStream())
                {
                    q.Save(ms, ImageFormat.Png);
                    var    serverPath = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/QRCodes");
                    string fileName   = string.Concat(offerId, ".png");
                    string path       = Path.Combine(serverPath, fileName);
                    if (!File.Exists(path))
                    {
                        FileSaveHelper.SaveBytesToFile(ms.ToArray(), path);
                    }
                    return(path);
                }
            }
        }
        public async Task <ActionResult> AddUpdateGame(DIBZ.Common.Model.GameCatalog request, HttpPostedFileBase file)
        {
            var gameCatalogLogic = LogicContext.Create <GameCatalogLogic>();

            var    serverPath = Server.MapPath("~/Uploads");
            string fileName   = string.Empty;

            if (file != null)
            {
                fileName = file.FileName;
            }
            var gameData = await gameCatalogLogic.AddUpdate(request, fileName);

            if (file != null)
            {
                var fileSizeInMB = file.ContentLength / 1024;
                var savePath     = Path.Combine(serverPath, gameData.GameImage.Id.ToString());
                if (fileSizeInMB >= 1024 * 1.65)
                {
                    var originalFilePath = Path.Combine(serverPath, (gameData.GameImage.Id + 100).ToString());
                    file.SaveAs(originalFilePath);
                    FileSaveHelper.ResizeTo(originalFilePath, 865, 500, savePath);
                    System.IO.File.Delete(originalFilePath);
                }
                else
                {
                    file.SaveAs(savePath);
                }
            }

            return(RedirectToAction("Index"));
        }
Exemple #6
0
        public async Task <ResponseBase <CustomerResponse> > Add()
        {
            var response = new ResponseBase <CustomerResponse>();

            if (!Request.Content.IsMimeMultipartContent())
            {
                response.success = false;
                response.message = "Unsupported Media Type";
                return(response);
            }
            var request     = "";
            var listFileNew = new List <FileAndMimeType>();

            var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

            foreach (var item in filesReadToProvider.Contents)
            {
                if (item.Headers.ContentDisposition.Name == "\"jsonKey\"")
                {
                    request = await item.ReadAsStringAsync();
                }
                else
                {
                    var obj = new FileAndMimeType();

                    var fileBytes = await item.ReadAsByteArrayAsync();

                    obj.file     = fileBytes;
                    obj.fileName = item.Headers.ContentDisposition.FileName;
                    listFileNew.Add(obj);
                }
            }


            // staff : who logged in into system, will upload customer information for registering for one customer
            var dataRequest  = JsonConvert.DeserializeObject <RequestBase>(request);
            var dataRequest1 = dataRequest.data;
            var data         = JsonConvert.DeserializeObject <CustomerDto>(dataRequest1.ToString());

            var helper  = new HelperBo();
            var isExist = helper.IsExistWhere("customers", " Idnumber = " + data.IdNumber);

            if (data.IdNumber == null)
            {
                response.message = "Customer Id can not be emty";
                response.success = false;
                return(response);
            }

            if (data.CIF == null)
            {
                response.message = "Customer Persnonal Identify can not be emty";
                response.success = false;
                return(response);
            }
            // if exist Customer => Still Save file to local, return success and message "Customer already existed";
            if (isExist.message == "1")
            {
                data.UrlPath = FileSaveHelper.SaveFileToLocal(listFileNew, data);

                if (data.UrlPath == null)
                {
                    // don't have file
                    response.message = "File not found.";
                    response.success = false;
                    return(response);
                }
                else
                {
                    response.message = "Customer already existed, only Insert the file";
                    response.success = true;
                    return(response);
                }
            }
            else
            {
                //else if not exist => get the file from request, upload to folder in server add new Customer => return result
                var folderCustomer = data.Name.ToString().Replace(" ", String.Empty).RemoveCharacterUnicode().Trim() + data.IdNumber.ToString().Trim();

                var folderStaff = data.StaffId.ToString().Trim();

                try
                {
                    data.UrlPath = FileSaveHelper.SaveFileToLocal(listFileNew, data);

                    if (data.UrlPath == null)
                    {
                        // don't have file
                        response.message = "File not found.";
                        response.success = false;
                        return(response);
                    }

                    //var res = CustomerHelperBo.Add(data);
                    var res = helper.Add("customers", data);
                    if (res.success)
                    {
                        response.message = "Insert new customer successfully.";
                        response.success = true;
                    }
                    else
                    {
                        response.message = "Can't insert new customer.";
                        response.success = false;
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteError(this.ToString(), "Stack Trace: " + ex.StackTrace);
                    LogUtil.WriteError(this.ToString(), "Message: " + ex.Message.ToString());
                    ErrorResponseBase errorResponse = new ErrorResponseBase();
                    errorResponse.errCode = ex.StackTrace.ToString();
                    errorResponse.message = ex.Message.ToString();
                    response.success      = false;
                    response.message      = "error";
                    response.error        = errorResponse;
                }
            }
            return(response);
        }
Exemple #7
0
 private IResult CarImageDeleteFile(CarImage carImage)
 {
     FileSaveHelper.Delete(carImage.ImagePath);
     return(new SuccessResult());
 }
Exemple #8
0
 private IResult CarImageAddFile(IFormFile file, CarImage carImage)
 {
     carImage.ImagePath = FileSaveHelper.Add(file);
     return(new SuccessResult());
 }
        public async Task <ActionResult> AddUpdateContent(FormCollection formData, HttpPostedFileBase file)
        {
            var    serverPath      = Server.MapPath("~/Uploads");
            string fileNewName     = string.Empty;
            string fileOrignalName = string.Empty;
            int    isUploaded      = 0;

            if (file != null)
            {
                Random rnd          = new Random();
                int    rendomNumber = rnd.Next(52);
                string extension    = Path.GetExtension(file.FileName);
                var    filename     = Path.GetFileNameWithoutExtension(file.FileName);
                fileNewName     = filename + rendomNumber + extension;
                fileOrignalName = file.FileName;

                var fileSizeInMB = file.ContentLength / 1024;
                var savePath     = Path.Combine(serverPath, fileNewName.ToString());
                if (fileSizeInMB >= 1024 * 1.65)
                {
                    var originalFilePath = Path.Combine(serverPath, (fileNewName).ToString());
                    file.SaveAs(originalFilePath);
                    FileSaveHelper.ResizeTo(originalFilePath, 865, 500, savePath);
                    System.IO.File.Delete(originalFilePath);
                    isUploaded = 1;
                }
                else
                {
                    file.SaveAs(savePath);
                    isUploaded = 1;
                }
            }

            int id = Convert.ToInt32(formData["Id"]);
            var newsFeedLogicLogic = LogicContext.Create <CompetitionLogic>();

            DIBZ.Common.Model.Competition request = new Common.Model.Competition();
            request.Id      = id;
            request.Name    = formData["txtname"];
            request.Title   = formData["txttitle"];
            request.Content = formData["txtcontent"];
            if (isUploaded == 1)
            {
                request.FileNewName     = fileNewName;
                request.FileOrignalName = fileOrignalName;
            }
            else
            {
                request.FileNewName     = "";
                request.FileOrignalName = "";
            }
            var status = formData["status"];

            if (status == "1")
            {
                request.IsActive = true;
            }
            else
            {
                request.IsActive = false;
            }

            await newsFeedLogicLogic.AddUpdate(request);

            return(RedirectToAction("Index"));
        }