Пример #1
0
        public ActionResult Save(Vessel vessel)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (DBDDACEntities3 dc = new DBDDACEntities3())
                {
                    if (vessel.VesselsId > 0)
                    {
                        //Edit
                        var v = dc.Vessels.Where(a => a.VesselsId == vessel.VesselsId).FirstOrDefault();
                        if (v != null)
                        {
                            v.VesselName = vessel.VesselName;
                            v.Terminal   = vessel.Terminal;
                            v.Country    = vessel.Country;
                        }
                    }
                    else
                    {
                        //Save
                        dc.Vessels.Add(vessel);
                    }
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #2
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                //update new pw if valid
                using (DBDDACEntities3 dc = new DBDDACEntities3())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated Successfully";
                    }
                }
            }
            else
            {
                message = "Something Invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
Пример #3
0
        public ActionResult ResetPassword(string id)
        {
            //Verify the password link

            //Find account associated with this link

            //redirect to reset password page

            using (DBDDACEntities3 dc = new DBDDACEntities3())
            {
                var user = dc.Users.Where(a => a.ResetPasswordCode == id).FirstOrDefault();

                if (user != null)
                {
                    ResetPasswordModel model = new ResetPasswordModel();
                    model.ResetCode = id;
                    return(View(model));
                }
                else
                {
                    //Invalid link
                    return(HttpNotFound());
                }
            }
        }
Пример #4
0
        public ActionResult ForgotPassword(string Email)
        {
            //Verify Email

            //Generate Reset Password Link

            //Send Email

            string message = "";

            using (DBDDACEntities3 dc = new DBDDACEntities3())
            {
                var account = dc.Users.Where(a => a.Email == Email).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    //unique identification number which is stored
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;

                    dc.Configuration.ValidateOnSaveEnabled = false;
                    dc.SaveChanges();
                    message = "Reset password link has been sent to your email.";
                }
                else
                {
                    message = "Account not found";
                }
            }

            ViewBag.Message = message;
            return(View());
        }
 public ActionResult Book(int id)
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var v = dc.Bookings.Where(a => a.BookingID == id).FirstOrDefault();
         return(View(v));
     }
 }
 public ActionResult GetBooking()
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var booking = dc.ScheduleBookings.OrderBy(a => a.Cargo).ToList();
         return(Json(new { data = booking }, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult GetVessels()
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var vessels = dc.Vessels.OrderBy(a => a.VesselName).ToList();
         return(Json(new { data = vessels }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #8
0
 public ActionResult Details(int id)
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var v = dc.Vessels.Where(a => a.VesselsId == id).FirstOrDefault();
         return(View(v));
     }
 }
Пример #9
0
 public bool IsEmailAlreadyExisted(string email)
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var v = dc.Users.Where(a => a.Email == email).FirstOrDefault();
         return(v != null);
     }
 }
Пример #10
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //saving data
            //Model Validation
            if (ModelState.IsValid)
            {
                //Email is already existed
                var isExist = IsEmailAlreadyExisted(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already existed");
                    return(View(user));
                }

                #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.IsEmailVerified = false;


                #region Save to Database
                using (DBDDACEntities3 dc = new DBDDACEntities3())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    //Send Email to User
                    SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                    message = "Registration Succeed, Account Activation link " +
                              "has been sent to your email: " + user.Email;
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Пример #11
0
 public ActionResult Delete(int id)
 {
     using (DBDDACEntities3 dc = new DBDDACEntities3())
     {
         var v = dc.Vessels.Where(a => a.VesselsId == id).FirstOrDefault();
         if (v != null)
         {
             return(View(v));
         }
         else
         {
             return(HttpNotFound());
         }
     }
 }
        public ActionResult Book(Booking booking)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (DBDDACEntities3 dc = new DBDDACEntities3())
                {
                    dc.Bookings.Add(booking);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #13
0
        public ActionResult DeleteVessel(int id)
        {
            bool status = false;

            using (DBDDACEntities3 dc = new DBDDACEntities3())
            {
                var v = dc.Vessels.Where(a => a.VesselsId == id).FirstOrDefault();
                if (v != null)
                {
                    dc.Vessels.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Пример #14
0
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            //if credentials valid
            string message = "";

            using (DBDDACEntities3 dc = new DBDDACEntities3())
            {
                var v = dc.Users.Where(a => a.Email == login.Email).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
                    {
                        //provided password is valid
                        int    timeout   = login.RememberMe ? 525600 : 20; // 1year
                        var    ticket    = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Schedules"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
Пример #15
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (DBDDACEntities3 dc = new DBDDACEntities3())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }