Пример #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Type,TakeOffDate,ImageUrl,CountryOriginID,CityDestinationID,Descriptions,Price,CountryDestinationCode,CityOriginCode,AirPlaneCode,TakeOffTime")] PlaneTicket planeTicket, HttpPostedFileBase Main_Image, string mydate)
        {
            if (Main_Image == null)
            {
                TempData["AirTicketError"] = "تصویری انتخاب نشده";
                return(RedirectToAction(nameof(Create)));
            }
            if (Main_Image != null)
            {
                if (!(Main_Image.ContentType == "image/jpeg" || Main_Image.ContentType == "image/png" || Main_Image.ContentType == "image/bmp"))
                {
                    TempData["ErrorAirPlane"] = "نوع تصویر غیر قابل قبول است";
                    return(RedirectToAction(nameof(Create)));
                }
                var    name     = Guid.NewGuid().ToString().Replace('-', '0') + "." + Main_Image.FileName.Split('.')[1];
                var    imageUrl = "/Upload/Tickets/" + name;
                string path     = Server.MapPath(imageUrl);
                Main_Image.SaveAs(path);
                planeTicket.ImageUrl = name;
            }

            if (ModelState.IsValid)
            {
                DateTime mydatee = DateChanger.ToGeorgianDateTime(mydate);
                planeTicket.TakeOffDate = mydatee;
                planeTicket.TakeOffTime = Convert.ToString(planeTicket.TakeOffTime);
                db.PlaneTickets.Add(planeTicket);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.CountryOriginID = new SelectList(db.Countries, "Id", "Name", planeTicket.CountryOriginID);
            return(View(planeTicket));
        }
Пример #2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Type,TakeOffDate,ImageUrl,CountryOriginID,CityDestinationID,Descriptions,Price,CountryDestinationCode,CityOriginCode")] PlaneTicket planeTicket, HttpPostedFileBase Main_Image, string mydate)
        {
            var item = await db.PlaneTickets.Where(s => s.Id == planeTicket.Id).FirstOrDefaultAsync();

            if (Main_Image != null)
            {
                if (item.ImageUrl != null)
                {
                    System.IO.File.Delete(Server.MapPath(String.Concat("~/Upload/Tickets/", item.ImageUrl)));
                }

                if (!(Main_Image.ContentType == "image/jpeg" || Main_Image.ContentType == "image/png" || Main_Image.ContentType == "image/bmp"))
                {
                    TempData["ErrorAirPlane"] = "نوع تصویر غیر قابل قبول است";
                    return(RedirectToAction(nameof(Edit)));
                }
                var    name     = Guid.NewGuid().ToString().Replace('-', '0') + "." + Main_Image.FileName.Split('.')[1];
                var    imageUrl = "/Upload/Tickets/" + name;
                string path     = Server.MapPath(imageUrl);
                Main_Image.SaveAs(path);
                item.ImageUrl = name;
            }

            if (ModelState.IsValid)
            {
                DateTime mydatee = DateChanger.ToGeorgianDateTime(mydate);
                planeTicket.TakeOffDate = mydatee;


                item.Price = planeTicket.Price;

                item.TakeOffDate            = mydatee;
                item.Type                   = planeTicket.Type;
                item.CountryOriginID        = planeTicket.CountryOriginID;
                item.CountryDestinationCode = planeTicket.CountryDestinationCode;
                item.CityDestinationID      = planeTicket.CityDestinationID;
                item.CityOriginCode         = planeTicket.CityOriginCode;


                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CountryOriginID = new SelectList(db.Countries, "Id", "Name", planeTicket.CountryOriginID);
            return(View(planeTicket));
        }
        // GET: Reports
        public ActionResult Index(string TakeOffDate1, string TakeOffDate2, int?Gender, int?State, int?ReportType, string txtsearch)
        {
            string[] formats = { "yyyy-MMM-dd" };
            DateTime dt;

            if (!string.IsNullOrEmpty(TakeOffDate1))
            {
                if (!DateTime.TryParse(TakeOffDate1, out dt))
                {
                    ViewData["Error"] = "فرمت تاریخ صحیح نیست";
                    return(View(db.Patients.ToList()));
                }
            }
            if (!string.IsNullOrEmpty(TakeOffDate2))
            {
                if (!DateTime.TryParse(TakeOffDate2, out dt))
                {
                    ViewData["Error"] = "فرمت تاریخ صحیح نیست";
                    return(View(db.Patients.ToList()));
                }
            }


            var result = db.Patients.ToList();

            if (string.IsNullOrEmpty(TakeOffDate1) == false && string.IsNullOrEmpty(TakeOffDate2) == false)
            {
                DateTime FromDate = DateChanger.ToGeorgianDateTime(TakeOffDate1);
                DateTime ToDate   = DateChanger.ToGeorgianDateTime(TakeOffDate2);
                result = result.Where(s => s.CreateDate >= FromDate && s.CreateDate <= ToDate).ToList();

                if (Gender != 3)
                {
                    var genderitem = (Gender)Gender;
                    result = result.Where(s => s.gender == genderitem).ToList();
                }
                if (State != 3)
                {
                    var stateitem = (State)State;
                    result = result.Where(s => s.State == stateitem).ToList();
                }
                if (ReportType != 3)
                {
                    if (ReportType == 0 && string.IsNullOrEmpty(txtsearch) == false)
                    {
                        result = result.Where(s => s.PrescribedDrugs.Contains(txtsearch)).ToList();
                    }
                    if (ReportType == 1 && string.IsNullOrEmpty(txtsearch) == false)
                    {
                        result = result.Where(s => s.DiseaseRecords.Contains(txtsearch)).ToList();
                    }
                }
                if (ReportType == 3 && string.IsNullOrEmpty(txtsearch) == false)
                {
                    result = result.Where(s => s.Name.Contains(txtsearch) || s.LastName.Contains(txtsearch) || s.Mobile == txtsearch).ToList();
                }

                ViewBag.count = "نتایج جستجو از این گزارش " + result.Count() + " مورد است .";
            }
            return(View(result));
        }