public int CreateItem(string insertedDic, string type)
        {
            //return the id back to the JS Datatable!
            switch (type)
            {
            case "tbl_userdata":
                tbl_userdata newUser = JsonConvert.DeserializeObject <tbl_userdata>(insertedDic);

                //Check if the email has been taken already
                int emailIsTaken = MollShopContext.CheckIfUserExists(newUser.fld_email);

                if (emailIsTaken == 0)
                {
                    //Email has not yet been taken

                    //Salt and Hash the password
                    newUser.fld_password = MollShopContext.SaltNHash(newUser.fld_password);

                    newUser.fld_userid = MollShopContext.CreateRow(newUser, type);

                    if (newUser.fld_dateofbirth == "")
                    {
                        newUser.fld_dateofbirth = null;
                    }
                    EsUpdater <tbl_userdata> .InsertDocument(newUser, "moll_users", "User", newUser.fld_userid.ToString());

                    return(newUser.fld_userid);
                }

                else
                {
                    //Email has been taken
                    return(-1);
                }

            case "tbl_servicedata":
                tbl_servicedata newService = JsonConvert.DeserializeObject <tbl_servicedata>(insertedDic);
                newService.fld_serviceid = MollShopContext.CreateRow(newService, type);
                EsUpdater <tbl_servicedata> .InsertDocument(newService, "moll_dataservices", "Services", newService.fld_serviceid.ToString());

                return(newService.fld_serviceid);

            case "tbl_labourerdata":
                tbl_labourerdata newLabourer = JsonConvert.DeserializeObject <tbl_labourerdata>(insertedDic);
                newLabourer.fld_labourerid = MollShopContext.CreateRow(newLabourer, type);
                EsUpdater <tbl_labourerdata> .InsertDocument(newLabourer, "moll_labourers", "Labourer", newLabourer.fld_labourerid.ToString());

                return(newLabourer.fld_labourerid);

            default:
                break;
            }

            return(0);
        }
예제 #2
0
        public IActionResult AlterTextField(string field, string newText)
        {
            int userId = (int)HttpContext.Session.GetInt32("UserId");

            if (field == "fld_password")
            {
                newText = MollShopContext.SaltNHash(newText);
            }
            MollShopContext.UpdateVarCharField("tbl_userdata", field, newText.ToString(), "fld_UserId", userId);

            return(RedirectToAction("MyAccount", "Account"));
        }