public ActionResult GetBillImage(int counterId, string dateStr) { UserBillModel userBillModel; var date = DateTime.ParseExact(dateStr, "dd/MM/yyyy", CultureInfo.CurrentCulture); using (var db = new GazDbContext()) { var repo = new BillsRepository(db); var userBill = repo.GetBillByDate(counterId, date); var user = db.Users.SingleOrDefault(o => o.Username == User.Identity.Name); var name = user != null ? string.Format("{0} {1}", user.FirstName, user.LastName) : User.Identity.Name; if (userBill == null) { return Content("no image"); } userBillModel = new UserBillModel(name, userBill.BillAmount.ToString(CultureInfo.InvariantCulture), userBill.CreateTime, userBill.ID.ToString(CultureInfo.InvariantCulture), userBill.CounterID.ToString()); } return this.UserBillImage(userBillModel); }
public static Image GenerateBillImage(UserBillModel model) { var fileName = AppDomain.CurrentDomain.BaseDirectory + "\\Images\\billsImage.png"; var valuesAndPositions = new [] { new TitleAndPosition(model.Name, new Rectangle(475, 117, 200, 50)), new TitleAndPosition(model.Amount, new Rectangle(650, 360, 200, 50)), new TitleAndPosition(model.Date.ToString("dd/MM/yy"), new Rectangle(60, 117, 400, 50)), new TitleAndPosition(model.Counter, new Rectangle(540, 117, 400, 50)), new TitleAndPosition(model.BillId, new Rectangle(810, 117, 400, 50)), }; return SetImage(fileName, valuesAndPositions); }
public FileResult UserBillImage(UserBillModel userBillModel) { var image = ImageService.GenerateBillImage(userBillModel); using (var streak = new MemoryStream()) { image.Save(streak, ImageFormat.Jpeg); return File(streak.ToArray(), "image/jpg"); } }