Ejemplo n.º 1
0
        public ActionResult <CustomResponseModel> PutLabel([FromForm] LabelRegistrationModel labelRegistrationModel)
        {
            LabelGlobalModel labelGlobalModel = new LabelGlobalModel();

            labelGlobalModel.Id              = GenerateUserId(labelRegistrationModel.Username + DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
            labelGlobalModel.LabelIcon       = labelRegistrationModel.LabelIcon;
            labelGlobalModel.LabelIconUrl    = new UserDataAccess().UploadLabelIcon(labelGlobalModel.LabelIcon, labelGlobalModel.Id);
            labelGlobalModel.LabelName       = labelRegistrationModel.LabelName;
            labelGlobalModel.Pass            = BCrypt.Net.BCrypt.HashPassword(labelRegistrationModel.Pass, BCrypt.Net.BCrypt.GenerateSalt());
            labelGlobalModel.Phone           = labelRegistrationModel.Phone;
            labelGlobalModel.Email           = labelRegistrationModel.Email;
            labelGlobalModel.Region          = labelRegistrationModel.Region;
            labelGlobalModel.Username        = labelRegistrationModel.Username;
            labelGlobalModel.EstDate         = labelRegistrationModel.EstDate;
            labelGlobalModel.IsEmailVerified = "false";
            labelGlobalModel.IsVerified      = "false";
            labelGlobalModel.Type            = "label";
            if (new UserDataAccess().RegisterLabel(labelGlobalModel))
            {
                new UserDataAccess().SendVerificationEmail(labelGlobalModel.LabelName, labelGlobalModel.Email, labelGlobalModel.Id);
                return(Ok(new CustomResponseModel()
                {
                    Code = "200", Phrase = "OK", Message = "Label Account Created"
                }));
            }
            return(BadRequest(new CustomResponseModel()
            {
                Code = "400", Phrase = "BadRequest", Message = "Label Account Creation Failed"
            }));
        }
Ejemplo n.º 2
0
        //LABEL REGISTRTION
        public bool RegisterLabel(LabelGlobalModel label)
        {
            bool InsertLabelMysql()
            {
                MysqlConnectionProvider dbConnection = new MysqlConnectionProvider();

                dbConnection.CreateQuery("INSERT INTO users(id, username, email, phone, pass, type, isemailverified) VALUES ('" + label.Id + "','" + label.Username + "','" + label.Email + "','" + label.Phone + "','" + label.Pass + "','" + label.Type + "','" + label.IsEmailVerified + "')");
                if ((dbConnection.DoNoQuery()) < 1)
                {
                    dbConnection.Dispose();
                    return(false);
                }
                dbConnection.Dispose();
                return(true);
            }

            bool InsertLabelMongo()
            {
                try
                {
                    var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("labels");
                    var document   = new BsonDocument
                    {
                        { "LabelId", label.Id },
                        { "LabelIconUrl", label.LabelIconUrl },
                        { "LabelName", label.LabelName },
                        { "EstDate", label.EstDate },
                        { "Region", label.Region },
                        { "IsVerified", label.IsVerified }
                    };
                    collection.InsertOne(document);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(InsertLabelMysql() && InsertLabelMongo());
        }