Пример #1
0
        public ActionResult GetAllItemMaster()
        {
            ItemMasterDal        itemMasterDal    = new ItemMasterDal();
            List <ItemMasterDto> lstItemMasterDto = itemMasterDal.GetAndEditItemMaster(0, 1);

            return(Json(lstItemMasterDto, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult SaveItemMaster()
        {
            try
            {
                ItemMasterDal itemMasterDal = new ItemMasterDal();
                ItemMasterDto itemMasterDto = new ItemMasterDto();
                itemMasterDto.ItemId = Convert.ToInt32(System.Web.HttpContext.Current.Request["ItemId"] == "" ? "0" : System.Web.HttpContext.Current.Request["ItemId"]);
                string Message, fileName, actualFileName;
                Message = fileName = actualFileName = string.Empty;
                if (Request.Files.Count > 0)
                {
                    var fileContent = Request.Files[0];
                    if (fileContent != null && fileContent.ContentLength > 0)
                    {
                        actualFileName = fileContent.FileName;
                        fileName       = Guid.NewGuid() + Path.GetExtension(fileContent.FileName);
                        using (Bitmap bmp = new Bitmap(fileContent.InputStream, false))
                        {
                            using (Graphics grp = Graphics.FromImage(bmp))
                            {
                                string     filePath  = Server.MapPath(Url.Content("~/fonts/watermark.png"));
                                Image      logoImage = Image.FromFile(filePath);
                                Image      TargetImg = Image.FromStream(fileContent.InputStream);
                                RectangleF rectf     = grp.VisibleClipBounds;
                                var        destX     = (TargetImg.Width - logoImage.Width) - 30;
                                var        destY     = (TargetImg.Height - logoImage.Height) - 30;
                                float      cxImage   = grp.DpiX * logoImage.Width /
                                                       logoImage.HorizontalResolution;
                                float cyImage = grp.DpiY * logoImage.Height /
                                                logoImage.VerticalResolution;
                                grp.DrawImage(logoImage, (rectf.Width - cxImage) / 2,
                                              (rectf.Height - cyImage) / 2);
                                // grp.DrawImage(logoImage, new Point(TargetImg.Width - logoImage.Width - 10, 10));
                                bmp.Save(Path.Combine(Server.MapPath("~/UploadImages/"), fileName));
                            }
                        }
                        itemMasterDto.ItemImage = fileName;
                    }
                    //fileContent.SaveAs(Path.Combine(Server.MapPath("~/UploadImages/"), fileName));
                }
                else
                {
                    fileName = "";
                    if (itemMasterDto.ItemId > 0)
                    {
                        dynamic imgFile = itemMasterDal.GetAndEditItemMaster(itemMasterDto.ItemId, 1);
                        itemMasterDto.ItemImage = Convert.ToString(imgFile[0].ItemImage);
                    }
                    else
                    {
                        itemMasterDto.ItemImage = fileName;
                    }
                }
                itemMasterDto.GroupId     = Convert.ToInt32(System.Web.HttpContext.Current.Request["GroupId"]);
                itemMasterDto.CategoryId  = Convert.ToInt32(System.Web.HttpContext.Current.Request["CategoryId"]);
                itemMasterDto.ItemName    = System.Web.HttpContext.Current.Request["ItemName"];
                itemMasterDto.ItemDetails = System.Web.HttpContext.Current.Request["ItemDetails"];
                itemMasterDto.ItemDesc    = System.Web.HttpContext.Current.Request["ItemDesc"];
                itemMasterDto.CreatedBy   = Convert.ToInt32(Session["AdminId"]);
                itemMasterDto.ModifiedBy  = Convert.ToInt32(Session["AdminId"]);
                itemMasterDto.IsActive    = 1;

                int i = itemMasterDal.SaveItemMaster(itemMasterDto);
                return(Json(i, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }