public IHttpActionResult PutClientsTable(int id, ClientsTable clientsTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != clientsTable.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public int UpdateFertilizersOfPocket(List <PocketFertilizerMapping> pocketFertilizersMappingList)
        {
            List <PocketFertilizerMapping> ExistingList = GetFertilizerByPocket(pocketFertilizersMappingList.ElementAt(0).PocketId.Value).ToList();

            List <PocketFertilizerMapping> CropsMappingToUpdate = pocketFertilizersMappingList.Select(x => x).Where(x => x.Id > 0).ToList();
            List <PocketFertilizerMapping> CropsMappingToInsert = pocketFertilizersMappingList.Select(x => x).Where(x => x.Id == 0).ToList();
            List <PocketFertilizerMapping> CropsMappingToDelete = ExistingList.Select(x => x).Where(x => !pocketFertilizersMappingList.Select(y => y.Id).Contains(x.Id)).ToList();

            InsertFertilizersOfPocket(CropsMappingToInsert);
            DeleteFertilizerOfPocket(CropsMappingToDelete);

            PocketFertilizerMapping pocketFertilizerMapping = null;

            CropsMappingToUpdate.ForEach(y =>
            {
                pocketFertilizerMapping = db.PocketFertilizerMappings.Select(x => x).Where(x => x.Id == y.Id).FirstOrDefault();
                if (pocketFertilizerMapping != null)
                {
                    pocketFertilizerMapping.FertilizerId = y.FertilizerId;
                    pocketFertilizerMapping.PocketId     = y.PocketId;
                }
            });

            return(db.SaveChanges());
        }
 public int InsertPocket(PocketInfo pocketInfo)
 {
     pocketInfo.CreatedDate = DateTime.Now;
     pocketInfo.UpdatedDate = DateTime.Now;
     pocketInfo.CreatedBy   = pocketInfo.CreatedBy;
     db.PocketInfoes.Add(pocketInfo);
     db.SaveChanges();
     return(pocketInfo.PocketID);
 }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "ID,LastName,FirstName,Age,Gender")] ClientsTable clientsTable)
        {
            if (ModelState.IsValid)
            {
                db.ClientsTables.Add(clientsTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(clientsTable));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Genre,Price")] Movy movy)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(movy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(movy));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,deviceType,deviceModel,deviceGrade")] Device device)
        {
            if (ModelState.IsValid)
            {
                db.Devices.Add(device);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(device));
        }
        public int DeletePocketVillageMappingListOfPocket(List <PocketVillageMapping> pocketVillageMappingList)
        {
            PocketVillageMapping pocketMapping = null;

            pocketVillageMappingList.ForEach(y =>
            {
                pocketMapping = db.PocketVillageMappings.Select(x => x).Where(x => x.Id == y.Id).FirstOrDefault();
                db.PocketVillageMappings.Remove(pocketMapping);
            });
            return(db.SaveChanges());
        }
 public FAapproval InsertFAapproval(FAapproval faApproval)
 {
     try
     {
         db.FAapprovals.Add(faApproval);
         db.SaveChanges();
         return(faApproval);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public IEnumerable <FAtargetVillageMapping> InsertFAtargetVillageMapping(IEnumerable <FAtargetVillageMapping> targetVillageMappingList)
 {
     try
     {
         db.FAtargetVillageMappings.AddRange(targetVillageMappingList);
         db.SaveChanges();
         return(targetVillageMappingList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int InsertFAAddressDetail(FAaddressDetail faAddressDetail)
 {
     try
     {
         db.FAaddressDetails.Add(faAddressDetail);
         db.SaveChanges();
         return(faAddressDetail.Id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int InsertFAdetail(FAdetail faDetail)
 {
     try
     {
         faDetail.FormNo = (faDetail.FirstName.Length > 3? faDetail.FirstName.Substring(0, 3):faDetail.FirstName.Substring(0, faDetail.FirstName.Length)) + faDetail.EnrollDate.Value.Day + faDetail.EnrollDate.Value.Month + faDetail.EnrollDate.Value.Year;
         db.FAdetails.Add(faDetail);
         db.SaveChanges();
         return(faDetail.Id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public IEnumerable <FAexperianceDetail> InsertFAexperienceDetail(IEnumerable <FAexperianceDetail> faExperienceDetailList)
 {
     try
     {
         foreach (var expDetail in faExperienceDetailList)
         {
             db.FAexperianceDetails.Add(expDetail);
         }
         db.SaveChanges();
         return(faExperienceDetailList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 13
0
 public IEnumerable <FAtargetDetail> InsertTargetsForFA(IEnumerable <FAtargetDetail> faTargetDetailList)
 {
     try
     {
         foreach (var targetDetail in faTargetDetailList)
         {
             db.FAtargetDetails.Add(targetDetail);
         }
         db.SaveChanges();
         return(faTargetDetailList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public ActionResult addEdit(Order orderData)
        {
            string message = "";

            orderData.UserID = currentUserID;
            orderData.Date   = DateTime.Today;
            db.Orders.Add(orderData);
            if (ModelState.IsValid)
            {
                db.SaveChanges();
                return(RedirectToAction("Transaction", "OrderTransaction"));
            }
            else
            {
                message = "Invalid Request";
            }
            return(RedirectToAction("Transaction"));
        }
Exemplo n.º 15
0
        public ActionResult ForgetPassword(string id)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            var account = DB.Users.Where(a => a.Email == id).FirstOrDefault();

            if (account != null)
            {
                //Send email for reset password
                Guid resetCode = Guid.NewGuid();
                //RegisterHelperFunc.OldURL = Request.Url.PathAndQuery;

                /*LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func();
                 * User returneUser = HelperFunc.UserExists(id);
                 * returneUser.navigateToLink = false;
                 * DB.Users.Attach(returneUser);
                 * var entry = DB.Entry(returneUser);
                 * entry.Property(e => e.navigateToLink).IsModified = true;
                 * // other changed properties
                 * DB.SaveChanges();*/
                RegisterHelperFunc.sendverification(account.Email, resetCode.ToString(), "Forget_Password/ResetPassword");
                account.ResetPasswordCode = resetCode;
                account.ResetPasswordDate = DateTime.Now;
                account.navigateToLink    = false;
                //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                //in our model class in part 1
                DB.Configuration.ValidateOnSaveEnabled = false;
                DB.SaveChanges();
                message = "Reset password link has been sent to your email id.";
            }
            else
            {
                message = "Account not found";
            }

            ViewBag.Message = message;
            //return RedirectToAction("Login", "LoginAndLogout");
            return(View());
        }
        public ActionResult Disblock(int id)
        {
            User user = db.Users.Where(x => x.ID == id).FirstOrDefault();

            user.State = "Active";
            var entry = db.Entry(user);

            entry.Property(e => e.State).IsModified = true;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IEnumerable <FAuploadedDocumentDetail> InsertUploadedDocumentDetailIst(IEnumerable <FAuploadedDocumentDetail> uplodedDocumentDetailList)
 {
     try
     {
         db.FAuploadedDocumentDetails.AddRange(uplodedDocumentDetailList);
         db.SaveChanges();
         return(uplodedDocumentDetailList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 18
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (DBentities db = new DBentities())
            {
                db.Configuration.ValidateOnSaveEnabled = false;//to avoid confirm password does not match problem on save

                var v = db.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
        public JsonResult SaveDataInDatabase(OrderTransactionModel orderData)
        {
            var result = false;

            //Check If User try to sell quantity more than you have it
            if (orderData.Type == false)
            {
                List <StockQuntity> query1 = (from ord in db.Orders
                                              where ord.UserID == currentUserID && ord.StockID == orderData.StockID && ord.Type == true
                                              group ord by new { ord.UserID, ord.StockID, ord.Type } into o
                                              select new StockQuntity {
                    quantity = o.Sum(x => x.Quantity)
                }).Take(1).ToList();
                int buy = 0;
                if (query1.Count > 0)
                {
                    buy = query1[0].quantity;
                }



                List <StockQuntity> query2 = (from ord in db.Orders
                                              where ord.UserID == currentUserID && ord.StockID == orderData.StockID && ord.Type == false
                                              group ord by new { ord.UserID, ord.StockID, ord.Type } into o
                                              select new StockQuntity {
                    quantity = o.Sum(x => x.Quantity)
                }).Take(1).ToList();

                int sell = 0;
                if (query2.Count > 0)
                {
                    sell = query2[0].quantity;
                }
                int selledBefore = 0;
                if (orderData.ID > 0)
                {
                    selledBefore = db.Orders.Where(Z => Z.ID == orderData.ID).FirstOrDefault().Quantity;
                    selledBefore = orderData.Quantity - selledBefore;
                }

                if ((buy - sell) < orderData.Quantity && orderData.ID <= 0)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                else if (((buy - sell) < selledBefore) && orderData.ID > 0)
                {
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            try
            {
                if (orderData.ID > 0)
                {
                    Order ord = db.Orders.SingleOrDefault(x => x.ID == orderData.ID);
                    ord.Quantity = orderData.Quantity;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    Order ord = new Order();
                    ord.UserID   = currentUserID;
                    ord.Date     = DateTime.Today;
                    ord.Quantity = orderData.Quantity;
                    ord.StockID  = orderData.StockID;
                    ord.Type     = orderData.Type;
                    db.Orders.Add(ord);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 20
0
 private int SaveChanges()
 {
     return(db.SaveChanges());
 }
Exemplo n.º 21
0
 public int LogException(ProjectException exception)
 {
     db.ProjectExceptions.Add(exception);
     db.SaveChanges();
     return(exception.Id);
 }
Exemplo n.º 22
0
        public ActionResult Login(loginModel model)
        {
            ViewBag.captchacount = 0.ToString();

            if (model.Username == null || model.Password == null)
            {
            }
            else
            {
                Session["username"] = model.Username.ToString();

                string hashedPassword = LogInOut_ForgPass_Func.GenerateSHA256String(model.Password);
                if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.State != "Active").FirstOrDefault() != null)
                {
                    ViewBag.message = "User Blocked";
                }
                else if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.IsEmailVerified == false).FirstOrDefault() != null)
                {
                    ViewBag.message = "User not verified";
                }

                else if (DB.Users.Where(x => x.UserName == model.Username).Where(x => x.Password == hashedPassword).FirstOrDefault() != null)
                {
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                        // Ticket version
                        model.Username,           // Username to be associated with this ticket
                        DateTime.Now,             // Date/time ticket was issued
                        DateTime.Now.AddDays(14), // Date and time the cookie will expire
                        false,                    // if user has chcked rememebr me then create persistent cookie
                        model.Username,
                        FormsAuthentication.FormsCookiePath);
                    string encrypted = FormsAuthentication.Encrypt(ticket);
                    var    cooki     = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                    cooki.Expires  = DateTime.Now.AddDays(14);
                    cooki.HttpOnly = true;
                    Response.Cookies.Add(cooki);

                    using (DBentities db = new DBentities())
                    {
                        LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func();
                        User resetCaptcha = HelperFunc.UsernameExists(model.Username);
                        resetCaptcha.CaptchaCounter = 0;
                        db.Users.Attach(resetCaptcha);
                        var ourentry = db.Entry(resetCaptcha);
                        ourentry.Property(e => e.CaptchaCounter).IsModified = true;
                        db.SaveChanges();
                    }
                    return(RedirectToAction("UserDashboard", "Dashboard"));
                }
                else
                {
                    ViewBag.message = "Wrong password";

                    LogInOut_ForgPass_Func HelperFunc = new LogInOut_ForgPass_Func();
                    User LoginUser = HelperFunc.UsernameExists(model.Username);
                    //User LoginUser = (from u in DB.Users
                    //          where u.Email == model.EmailID
                    //          select u).FirstOrDefault();
                    if (LoginUser != null)
                    {
                        LoginUser.CaptchaCounter++;
                        ViewBag.captchacount = LoginUser.CaptchaCounter.ToString();
                        DB.Users.Attach(LoginUser);
                        var entry = DB.Entry(LoginUser);
                        entry.Property(e => e.CaptchaCounter).IsModified = true;
                        // other changed properties
                        DB.SaveChanges();
                        if (LoginUser.CaptchaCounter > 3)
                        {
                            return(RedirectToAction("Captcha"));
                        }
                    }
                    else
                    {
                        ViewBag.message = "Wrong username or password";
                    }
                }
            }
            return(View());
        }
Exemplo n.º 23
0
        public ActionResult Register([Bind(Exclude = "Admin,State,IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //
            //model validation
            if (ModelState.IsValid)
            {
                #region    //email already exists
                //User exist = RegisterHelperFunc.UserExists(user.Email);
                User emailExist    = DB.Users.Where(x => x.Email == user.Email).FirstOrDefault();
                User usernameExist = RegisterHelperFunc.UsernameExists(user.UserName);
                if (emailExist != null && usernameExist != null)
                {
                    ViewBag.validate = "Username and Email already exist";
                    return(View(user));
                }
                else if (emailExist != null)
                {
                    ViewBag.validate = "Email already exist";
                    ModelState.AddModelError("Email Exists", "Email already exists");
                    return(View(user));
                }
                else if (usernameExist != null)
                {
                    ViewBag.validate = "Username already exist";
                    return(View(user));
                }
                #endregion
                #region Generate Activation code
                user.ActivationCode = Guid.NewGuid();
                #endregion
                #region password hashing
                user.Password = LogInOut_ForgPass_Func.GenerateSHA256String(user.Password);
                //user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion

                #region answer hashing
                user.QuestionAnswer = LogInOut_ForgPass_Func.GenerateSHA256String(user.QuestionAnswer);
                #endregion

                user.IsEmailVerified = false;
                user.CaptchaCounter  = 0;
                user.navigateToLink  = false;
                #region save to database
                // using (DBentities db = new DBentities())
                //{
                //   user.State = "active";
                ///  string ques = Request.Params[6].ToString();
                // user.Question = (from q in db.Questions
                //                 where q.QTextEnglish == ques
                //                select q).FirstOrDefault();
                user.Admin = false;
                user.State = "Active";
                DB.Users.Add(user);
                DB.SaveChanges();

                //send email to user
                RegisterHelperFunc.OldURL = Request.Url.PathAndQuery;
                RegisterHelperFunc.sendverification(user.Email, user.ActivationCode.ToString());
                message = "successfully registered. Account activation link has been sent to email: " + user.Email;
                Status  = true;
                // }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            //generate activation code

            //password  hashing


            //save data to database
            ViewBag.Message   = message;
            ViewBag.Status    = Status;
            ViewBag.questions = DB.Questions.ToList();
            return(View(user));
            //return Content("ok");
        }