コード例 #1
0
        public ActionResult Edit(InquiryViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.updated_by = UserHelpers.GetUser().id;

                    SetRequestURL(APIURL.INQUIRY_UPDATE, Method.POST);
                    request.AddBody(model);

                    var response = rest.Execute(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        SetMessage(Message.SuccessfulUpdate("Inquiry #" + model.id), MESSAGE_TYPE.SUCCESS);

                        return RedirectToAction("Details", new { id = model.id });
                    }
                    else
                    {
                        ModelState.AddModelError("", response.Content);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            SetTitle("Inquiry - " + model.id);
            return View(model);
        }
コード例 #2
0
        public ActionResult Inquire(InquiryViewModel model)
        {
            try
            {
                long user = UserHelpers.GetUser().id;
                if (user == 0)
                {
                    this.Session["INQUIRY"] = model;
                    this.Session["MESSAGE"] = new CustomException(Notify.INQUIRY, MESSAGE_TYPE.INFO);
                    return RedirectToAction("Index", "Register");
                }
                else
                {
                    ModelState.Remove("first_name");
                    ModelState.Remove("last_name");
                    ModelState.Remove("email");
                    model.created_by = user;
                }

                if (ModelState.IsValid)
                {
                    SetRequestURL(APIURL.INQUIRY_INSERT, Method.POST);
                    request.AddBody(model);
                    var response = rest.Execute(request);

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        long id = JsonConvert.DeserializeObject<long>(response.Content);
                        SetMessage(Notify.INQUIRY_SUCCESS(id), MESSAGE_TYPE.SUCCESS);
                        return RedirectToAction("Index");
                    }
                    else
                    {
                        ModelState.AddModelError("", response.Content);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            SetRequestURL(APIURL.INQUIRY_CONTACT_US, Method.GET);
            var res = rest.Execute(request);

            if (res.StatusCode == HttpStatusCode.OK)
            {
                SetTitle("Contact Us");
                InquiryContactUsCollectionViewModel mod = JsonConvert.DeserializeObject<InquiryContactUsCollectionViewModel>(res.Content);

                var m = new InquiryContactUsViewModel
                {
                    inquiry = new InquiryViewModel(),
                    contact_us = mod.contacts.ToPagedList(1, 8)
                };

                ViewBag.type = new SelectList(mod.types, "id", "name", model.type);
                return View("Index", m);
            }
            else
            {
                return CustomMessage(res.Content);
            }
        }