public ActionResult ViewPost(int id)
        {
            Post post   = new Post();
            var  userID = Convert.ToInt32(Session["id"]);
            bool exist;


            using (MyDatabaseEntities db = new MyDatabaseEntities())
            {
                post  = db.Posts.Where(x => x.PostID == id).FirstOrDefault();
                exist = db.Likes.Any(x => x.PostId == id && x.UserId == userID);
                if (exist == false)
                {
                    ViewBag.Like = false;
                }
                else
                {
                    ViewBag.Like = true;
                }

                post.Likes = db.Likes.Count(x => x.PostId == id);
                db.Entry(post).Property("Likes").IsModified = true;
                db.SaveChanges();


                post.Comments = db.Comments.Count(x => x.PostId == id);
                db.Entry(post).Property("Comments").IsModified = true;
                db.SaveChanges();
            }

            return(View(post));
        }
Example #2
0
        public IHttpActionResult PutTransaction(int id, Transaction transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != transaction.Id)
            {
                return(BadRequest());
            }

            db.Entry(transaction).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TransactionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
 public ActionResult Edit(ProductGalary productgalary)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productgalary).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productgalary));
 }
Example #4
0
 public ActionResult Register(Admin admin)
 {
     admin.IsValid  = false;
     admin.Password = Helper.PasswordHelper.HashPassword(admin.Password);
     db.Admin.Add(admin);
     db.Configuration.ValidateOnSaveEnabled = false;
     db.SaveChanges();
     BuildEmailTemplate(admin.Id);
     return(RedirectToAction("Login", "Home"));
 }
Example #5
0
        public ActionResult SaveFormData(AccountInfoFormDataVM formData)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = 400;
                    return(Json(ErrorMessageVM.CHECK_DATA_FAIL));
                }

                using (var ctx = new MyDatabaseEntities())
                    using (var txn = ctx.Database.BeginTransaction())
                    {
                        //## 若已存在則更新,不存在則新增
                        var info = ctx.Account.Find(formData.accountInfo.name);
                        if (info != null)
                        {
                            //# 已存在則更新
                            //info.name = formData.accountInfo.name; // PK
                            info.email       = formData.accountInfo.email ?? "";
                            info.mobilePhone = formData.accountInfo.mobilePhone ?? "";
                            info.birthday    = formData.userInfo.birthday;
                            info.contactTime = formData.userInfo.contactTime;
                            info.remark      = formData.userInfo.remark;

                            ctx.SaveChanges();
                            txn.Commit();
                        }
                        else
                        {
                            //# 不存在則新增
                            Account newInfo = new Account()
                            {
                                name        = formData.accountInfo.name,
                                email       = formData.accountInfo.email ?? "",
                                mobilePhone = formData.accountInfo.mobilePhone ?? "",
                                birthday    = formData.userInfo.birthday,
                                contactTime = formData.userInfo.contactTime,
                                remark      = formData.userInfo.remark
                            };

                            ctx.Account.Add(newInfo);
                            ctx.SaveChanges();
                            txn.Commit();
                        }
                    }

                return(Json(ErrorMessageVM.SUCCESS));
            }
            catch (Exception ex)
            {
                Response.StatusCode = 500;
                return(Json(new ErrorMessageVM(ex.Message)));
            }
        }
        public ActionResult Create([Bind(Include = "Id,Название_группы,Примечание")] Группы_задач группы_задач)
        {
            if (ModelState.IsValid)
            {
                db.Группы_задач.Add(группы_задач);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(группы_задач));
        }
 public IHttpActionResult PostActivity(Activity activity)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     //db.Activities.Add(activity);
     db.Activity.Add(activity);
     db.SaveChanges();
     return(CreatedAtRoute("DefaultApi", new { id = activity.Id }, activity));
 }
        public ActionResult Create([Bind(Include = "Id,Название_пункта,Адрес,Регулярность")] Пункт_доставки пункт_доставки)
        {
            if (ModelState.IsValid)
            {
                db.Пункт_доставки.Add(пункт_доставки);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(пункт_доставки));
        }
        public ActionResult Create(User_Folder user_folder)
        {
            if (ModelState.IsValid)
            {
                db.User_Folder.Add(user_folder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user_folder));
        }
Example #10
0
        public ActionResult Create(Thread thread)
        {
            if (ModelState.IsValid)
            {
                db.Thread.Add(thread);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(thread));
        }
Example #11
0
        public ActionResult Create([Bind(Include = "CustomerId,Name,Address,Phone,OrderDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "Id,name,address,city,email,phonne")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Example #13
0
        public ActionResult Create([Bind(Include = "Id,fio,license_expire,categories")] Voditel voditel)
        {
            if (ModelState.IsValid)
            {
                db.Voditel.Add(voditel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(voditel));
        }
        public ActionResult Create([Bind(Include = "Id,Название_маршрута,Примечание")] Маршрут маршрут)
        {
            if (ModelState.IsValid)
            {
                db.Маршрут.Add(маршрут);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(маршрут));
        }
        public ActionResult Create([Bind(Include = "OrderID,OrderNo,OrderDate,Description")] OrderMaster orderMaster)
        {
            if (ModelState.IsValid)
            {
                db.OrderMasters.Add(orderMaster);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(orderMaster));
        }
Example #16
0
        public ActionResult Create(message Message)
        {
            if (ModelState.IsValid)
            {
                db.message.Add(Message);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(Message));
        }
Example #17
0
        public ActionResult Create([Bind(Include = "name,email,mobilePhone,birthday,contactTime,remark")] Account account)
        {
            if (ModelState.IsValid)
            {
                db.Account.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
        public ActionResult Create([Bind(Include = "ProductID,CategoryID,ProductName")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Example #20
0
        public ActionResult Create([Bind(Include = "Id,Название_типа")] Тип_ТС тип_ТС)
        {
            if (ModelState.IsValid)
            {
                db.Тип_ТС.Add(тип_ТС);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(тип_ТС));
        }
        public ActionResult Create([Bind(Include = "DoctorID,FirstName,LastName,Job,Directory,Date")] Doctor doctor)
        {
            if (ModelState.IsValid)
            {
                db.Doctors.Add(doctor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(doctor));
        }
Example #22
0
        public ActionResult Create(users users)
        {
            if (ModelState.IsValid)
            {
                db.users.Add(users);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(users));
        }
        public ActionResult Create([Bind(Include = "LocationID,Title,Lat,Long,Address,Phone,ImagePath,Detail,Price,Bed,Wardrobe,Conditioner,Desk,Toilet,Refrigrator,Wifi")] Location location)
        {
            if (ModelState.IsValid)
            {
                db.Locations.Add(location);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
        public ActionResult Create([Bind(Include = "Id,Название_автомобиля,Госномер,Примечание,Тип_ТСID")] Автомобиль автомобиль)
        {
            if (ModelState.IsValid)
            {
                db.Автомобиль.Add(автомобиль);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Тип_ТСID = new SelectList(db.Тип_ТС, "Id", "Название_типа", автомобиль.Тип_ТСID);
            return(View(автомобиль));
        }
        public ActionResult Create([Bind(Include = "PacjentID,FirstName,LastName,Choroba,Date,Telefon,DoctorID")] Pacjent pacjent)
        {
            if (ModelState.IsValid)
            {
                db.Pacjents.Add(pacjent);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DoctorID = new SelectList(db.Doctors, "DoctorID", "FirstName", pacjent.DoctorID);
            return(View(pacjent));
        }
        public ActionResult Create([Bind(Include = "OrderDetailsID,OrderID,ProductID,Rate,Quantity")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                db.OrderDetails.Add(orderDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID = new SelectList(db.OrderMasters, "OrderID", "OrderNo", orderDetail.OrderID);
            return(View(orderDetail));
        }
        public ActionResult Create([Bind(Include = "Id,Название_задачи,Группа_задачID,Примечание")] Задача задача)
        {
            if (ModelState.IsValid)
            {
                db.Задача.Add(задача);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Группа_задачID = new SelectList(db.Группы_задач, "Id", "Название_группы", задача.Группа_задачID);
            return(View(задача));
        }
Example #28
0
        public ActionResult Create([Bind(Include = "Id,ФИО,E_mail,Телефон,Пункт_доставкиID")] Получатель получатель)
        {
            if (ModelState.IsValid)
            {
                db.Получатель.Add(получатель);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Пункт_доставкиID = new SelectList(db.Пункт_доставки, "Id", "Название_пункта", получатель.Пункт_доставкиID);
            return(View(получатель));
        }
Example #29
0
        public ActionResult Create([Bind(Include = "OrderId,ProductName,Quantity,Price,Amount,CustomerId")] Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", order.CustomerId);
            return(View(order));
        }
        public void Sign()
        {
            User user = new User();

            user.FirstName       = "r";
            user.LastName        = "rr";
            user.EmailID         = "*****@*****.**";
            user.Password        = "******";
            user.ConfirmPassword = "******";

            bool   Status  = false;
            string message = "";
            string succ;

            //
            // Model Validation


            #region //Email is already Exist
            var isExist = IsEmailExist(user.EmailID);
            if (isExist)
            {
                succ = "Email already exist";
                Assert.IsNotNull(succ);
            }
            #endregion

            #region Generate Activation Code
            user.ActivationCode = Guid.NewGuid();
            #endregion

            #region  Password Hashing
            user.Password        = Crypto.Hash(user.Password);
            user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); //
            #endregion
            user.IsEmailVerfied = false;

            #region Save to Database
            db.Users.Add(user);
            db.SaveChanges();

            //Send Email to User
            SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString());
            message = "Registration successfully done. Account activation link " +
                      " has been sent to your email id:" + user.EmailID;
            Status = true;
            #endregion


            Assert.IsNotNull(user);
        }
 public JsonResult Register(User u)
 {
     string message = "";
     //Here we will save data to the database
     if (ModelState.IsValid)
     {
         using (MyDatabaseEntities dc = new MyDatabaseEntities())
         {
             //check username available
             var user = dc.Users.Where(a => a.Username.Equals(u.Username)).FirstOrDefault();
             if (user == null)
             {
                 //Save here
                 dc.Users.Add(u);
                 dc.SaveChanges();
                 message = "Success";
             }
             else
             {
                 message = "Username not available!";
             }
         }
     }
     else
     {
         message = "Failed!";
     }
     return new JsonResult { Data = message,  JsonRequestBehavior = JsonRequestBehavior.AllowGet };
 }
        public JsonResult SaveFiles(string description)
        {
            string Message, fileName, actualFileName;
            Message = fileName = actualFileName = string.Empty;
            bool flag = false;
            if (Request.Files != null)
            {
                var file = Request.Files[0];
                actualFileName = file.FileName;
                fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                int size = file.ContentLength;

                try
                {
                    file.SaveAs(Path.Combine(Server.MapPath("~/UploadedFiles"), fileName));

                    UploadedFile f = new UploadedFile
                    {
                        FileName = actualFileName,
                        FilePath = fileName,
                        Description = description,
                        FileSize = size
                    };
                    using (MyDatabaseEntities dc = new MyDatabaseEntities())
                    {
                        dc.UploadedFiles.Add(f);
                        dc.SaveChanges();
                        Message = "File uploaded successfully";
                        flag = true;
                    }
                }
                catch (Exception)
                {
                    Message = "File upload failed! Please try again";
                }

            }
            return new JsonResult { Data = new { Message = Message, Status = flag } };
        }