Пример #1
0
        public ActionResult Create(CreateJourneyModel cjm) {
			using(IJourneyDao dao = DaoFactory.Instance.GetJourneyDao()) {
                if (ModelState.IsValid) {
                    byte[] pic = null;
                    if (cjm.Picture != null && cjm.Picture.ContentLength > 0) {
                        Image orig = Image.FromStream(cjm.Picture.InputStream);
                        int nH = 100;
                        int nW = 185;
                        Image resized = new Bitmap(nW, nH);
                        double ratioH = orig.Height > nH ? (double)nH / orig.Height : 1;
                        double ratioW = orig.Width > nW ? (double)nW / orig.Width : 1;
                        double ratio = ratioH < ratioW ? ratioH : ratioW;
                        int h = (int)(orig.Height * ratio);
                        int w = (int)(orig.Width * ratio);
                        using (Graphics g = Graphics.FromImage(resized)) {
                            g.FillRectangle(Brushes.White, 0, 0, nW, nH);
                            g.SmoothingMode = SmoothingMode.HighQuality;
                            g.DrawImage(orig, (nW - w) / 2, (nH - h) / 2, w, h);
                        }
                        MemoryStream ms = new MemoryStream();
                        resized.Save(ms, ImageFormat.Jpeg);
                        pic = ms.ToArray();
                        orig.Dispose();
                        cjm.Picture.InputStream.Dispose();
                        resized.Dispose();
                        ms.Dispose();
                    }
                    HttpFileCollectionBase hfcb = Request.Files;
                    try {
                        dao.Add(cjm.Name, cjm.From, cjm.To, User.Identity.Name, cjm.DateFrom, cjm.DateTo, (double)cjm.Amount, pic);
                    } catch (System.ServiceModel.FaultException fe) {
                        cjm.FaultMessage = fe.Message;
                        return View(cjm);
                    }
                    currentlyCreatedJourneyName = cjm.Name;
                    return RedirectToAction("Index");
                } else {
                    return View(cjm);
                }
            }
        }
Пример #2
0
 //
 // GET: /Journey/Create
 
 public ActionResult Create() {
     CreateJourneyModel cjm = new CreateJourneyModel();
     cjm.DateFrom = DateTime.Now;
     cjm.DateTo = cjm.DateFrom.AddDays(7);
     return View(cjm);
 }