Exemple #1
0
        public static string RegisterNewUser(tbl_userdata user)
        {
            string activationCode = generateActivationCode();

            try
            {
                Dictionary <string, Object> dic = new Dictionary <string, Object>();
                dic.Add("in_userName", user.fld_username);
                dic.Add("in_password", SaltNHash(user.fld_password));
                dic.Add("in_firstName", user.fld_firstname);
                dic.Add("in_lastName", user.fld_lastname);
                dic.Add("in_gender", user.fld_gender);
                dic.Add("in_address", user.fld_address);
                dic.Add("in_zipCode", user.fld_zipcode);
                dic.Add("in_dob", user.fld_dateofbirth);
                dic.Add("in_phoneNumber", user.fld_phonenumber);
                dic.Add("in_emailAddress", user.fld_email);
                dic.Add("in_activationCode", activationCode);
                dic.Add("in_isActivated", false);
                dic.Add("out_userId", 0);
                dic = ProcedureCall <int> .ExecuteNonQuery(dic, "user_Register");

                user.fld_activationcode = activationCode;
                user.fld_userid         = Convert.ToInt32(dic["out_userId"]);
                EsUpdater <tbl_userdata> .InsertDocument(user, "moll_users", "User", dic["out_userId"].ToString());

                return(activationCode);
            }
            catch (Exception e)
            {
                return("Db Error!");
            }
        }
        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);
        }
        public OLS CreateOLS(string offeredService, string serviceId, string labourerId)
        {
            tbl_servicedata         service           = EsServiceQuery.FindById(Convert.ToInt32(serviceId));
            tbl_labourerdata        labourer          = EsLabourerQuery.FindById(Convert.ToInt32(labourerId));
            tbl_offeredservicesdata offeredServiceObj = JsonConvert.DeserializeObject <tbl_offeredservicesdata>(offeredService);

            offeredServiceObj.fld_labourerid = labourer.fld_labourerid;
            offeredServiceObj.fld_serviceid  = service.fld_serviceid;

            offeredServiceObj.fld_offeredserviceid = MollShopContext.CreateRow(offeredServiceObj, "tbl_offeredservicesdata");

            OLS ols = ConstructOLS(service, labourer, offeredServiceObj);

            //Because ElasticSearch does not support decimal numbers, we must multiply the cost by a 100
            ols.fld_cost = ols.fld_cost * 100;

            EsUpdater <OLS> .InsertDocument(ols, "moll_ols", "OLS", ols.fld_offeredserviceid.ToString());

            //return the OfferedLabourerService, so we can later render it into the Datatable on the ManageOLS page
            //We must divide the cost by a 100 again, to render it correctly

            ols.fld_cost = ols.fld_cost / 100;
            return(ols);
        }