Beispiel #1
0
        public UserDTO mappingUserObject(UserDb user, PersonDb person, WorkshopDb workshop)
        {
            UserDTO userData = new UserDTO();

            userData.user_id     = user.userId;
            userData.accessToken = user.accessToken;
            userData.countryCode = Convert.ToInt32(user.countryCode);
            userData.phoneNumber = user.phoneNumber;
            userData.userType    = user.userType;
            userData.userImage   = user.userImage;


            userData.firstName = person.firstName;
            userData.lastName  = person.lastName;


            userData.shopNumber = Convert.ToInt32(workshop.shopNumber);
            userData.shopName   = workshop.shopName;
            userData.cityId     = workshop.cityId;
            userData.cityName   = workshop.cityName;
            userData.address    = workshop.address;
            userData.Lat        = workshop.lat;
            userData.Lng        = workshop.lng;



            return(userData);
        }
        public ActionResult Edit(Guid id)
        {
            using (WorkshopDb db = new WorkshopDb())
            {
                var query = db.GuestBooks.Where(i => i.Id == id);

                if (!query.Any())
                {
                    return(HttpNotFound());
                }

                return(View("Edit", query.First()));
            }
        }
        // implement Partial View to display replies.
        public ActionResult IndexReply(Guid PostId)
        {
            using (WorkshopDb db = new WorkshopDb())
            {
                if (PostId == null)
                {
                    return(new EmptyResult());
                }
                else
                {
                    var query = db.GuestBooks
                                .Where(i => i.IdReply == PostId)
                                .OrderByDescending(i => i.DateCreated);

                    return(PartialView("_RepliesView", query.ToList()));
                }
            }
        }
        //public ActionResult Create(GuestBook Model, Guid? id = null)
        public ActionResult Create(Guid?id = null, string Magic = null)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View();
            //}

            var Model    = new GuestBook();
            var identity = Request.RequestContext.HttpContext.User.Identity as FormsIdentity;
            var o        = JObject.Parse(identity.Ticket.UserData);

            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                if (id == null)
                {
                    Model.Id          = Guid.NewGuid();
                    Model.DateCreated = DateTime.Now;
                    Model.Subject     = Request.Form["Subject"];
                    Model.Name        = o.Property("name").ToObject(typeof(string)).ToString();
                    Model.Email       = o.Property("email").ToObject(typeof(string)).ToString();
                    Model.Body        = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);

                    db.GuestBooks.Add(Model);
                }
                else
                {
                    Model.Id          = Guid.NewGuid();
                    Model.IdReply     = id.Value;
                    Model.Subject     = Request.Form["Subject"];
                    Model.Name        = o.Property("name").ToObject(typeof(string)).ToString();
                    Model.Email       = o.Property("email").ToObject(typeof(string)).ToString();
                    Model.Body        = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);
                    Model.DateCreated = DateTime.Now;

                    db.GuestBooks.Add(Model);
                }

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(Guid id)
        {
            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                // query item.
                var query = db.GuestBooks.Where(i => i.Id == id);

                if (!query.Any())
                {
                    return(HttpNotFound());
                }

                var dbModel = query.First();
                db.GuestBooks.Remove(dbModel);

                // change tracking service lets it valid.
                db.SaveChanges();
            }

            return(new EmptyResult());
        }
        //public ActionResult Edit(GuestBook Model, Guid id)
        public ActionResult Edit(Guid id, string Magic = null)
        {
            //if (!ModelState.IsValid)
            //{
            //    if (string.IsNullOrEmpty(Model.Subject) ||
            //        string.IsNullOrEmpty(Model.Body))
            //        return View();
            //}

            if (string.IsNullOrEmpty(Request.Form["Subject"]) ||
                string.IsNullOrEmpty(Request.Unvalidated.Form["Body"]))
            {
                return(View());
            }

            // create data.
            using (WorkshopDb db = new WorkshopDb())
            {
                // query item.
                var query = db.GuestBooks.Where(i => i.Id == id);

                if (!query.Any())
                {
                    return(HttpNotFound());
                }

                var dbModel = query.First();

                // modify data.
                dbModel.Subject = Request.Form["Subject"];
                dbModel.Body    = Sanitizer.GetSafeHtmlFragment(Request.Unvalidated.Form["Body"]);

                // change tracking service lets it valid.
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        // GET: Home
        public ActionResult Index(Guid?id, int?Page = 1)
        {
            using (WorkshopDb db = new WorkshopDb())
            {
                IQueryable <GuestBook> query = null;

                if (id == null)
                {
                    query = db.GuestBooks.Where(i => i.IdReply == Guid.Empty);
                    var pageQuery = query.OrderByDescending(i => i.DateCreated).ToPagedList(Page.Value, 5);

                    if (Request.IsAjaxRequest())
                    {
                        return(PartialView("_ThreadView", pageQuery));
                    }
                    else
                    {
                        return(View("Thread", pageQuery));
                    }
                }
                else
                {
                    query          = db.GuestBooks.Where(i => i.Id == id.Value);
                    ViewBag.PostId = id.Value.ToString();

                    if (query.Any())
                    {
                        return(View("ThreadReplyView", query.First()));
                    }
                    else
                    {
                        return(HttpNotFound());
                    }
                }
            }
        }