public async Task <PostResponseModel> RegisterVendor(RegisterVendorRequestModel vendorDetailsRequestModel)
        {
            PostResponseModel postResponseModel = new PostResponseModel();

            RegisterVendor registerUser = new RegisterVendor()
            {
                VendorName     = vendorDetailsRequestModel.VendorName,
                VendorEmail    = vendorDetailsRequestModel.VendorEmail,
                VendorMobile   = vendorDetailsRequestModel.VendorMobile,
                VendorLandline = vendorDetailsRequestModel.VendorLandline,
                AddressLine    = vendorDetailsRequestModel.AddressLine,
                City           = vendorDetailsRequestModel.City,
                State          = vendorDetailsRequestModel.State,
                PinCode        = vendorDetailsRequestModel.PinCode
            };

            var registerVendorResponse = await _vendorAuthenticationRepository.RegisterVendor(registerUser);

            postResponseModel.IsAlreadyExists = registerVendorResponse.IsUserExists;

            if (!postResponseModel.IsAlreadyExists && registerVendorResponse.Success)
            {
                var emailBody    = "Hello !!!";
                var emailSubject = "Vendor Register";

                var emailResponse = await _messageSenderUtility.SendEmail(emailBody, emailSubject, vendorDetailsRequestModel.VendorEmail);

                postResponseModel.Success = emailResponse.IsEmailSend;

                //Log email
                EmailLogs emailLogDetails = new EmailLogs()
                {
                    FromEmailAddress = emailResponse.FromEmailAddress,
                    ToEmailAddress   = emailResponse.ToEmailAddress,
                    Subject          = emailSubject,
                    Body             = emailBody,
                    IsProduction     = emailResponse.IsProductionEnvironment,
                    IsSend           = emailResponse.IsEmailSend,
                    ApplicationId    = (int)ApplicationType.Vendor,
                    FromUserType     = "System",
                    ToUserType       = "Vendor",
                    ToUserId         = registerVendorResponse.Content.VendorId
                };

                await _loggingRepository.LogEmailTransaction(emailLogDetails);
            }
            else
            {
                postResponseModel.Success = registerVendorResponse.Success;
            }

            return(postResponseModel);
        }
 public ActionResult Edit(RegisterVendor registerVendor, int id)
 {
     if (ModelState.IsValid)
     {
         Vendor vendor = db.Vendors.Find(id);
         vendor.FirstName       = registerVendor.FirstName;
         vendor.LastName        = registerVendor.LastName;
         vendor.Mobile          = registerVendor.Mobile;
         vendor.Email           = registerVendor.Email;
         vendor.Password        = registerVendor.Password;
         db.Entry(vendor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(registerVendor));
 }
        public ActionResult Create(RegisterVendor registerVendor)
        {
            if (ModelState.IsValid)
            {
                Vendor vendor = new Vendor()
                {
                    FirstName = registerVendor.FirstName,
                    LastName  = registerVendor.LastName,
                    Mobile    = registerVendor.Mobile,
                    Email     = registerVendor.Email,
                    Password  = registerVendor.Password,
                    CreatedOn = DateTime.Now,
                };
                db.Vendors.Add(vendor);
                db.SaveChanges();
                Session["vendorId"] = vendor.VendorId;
                return(RedirectToAction("Create", "BranchVendors"));
            }

            return(View(registerVendor));
        }
Beispiel #4
0
        public IActionResult getVendor(int Id)
        {
            var data  = new User();
            var model = new RegisterVendor();

            try
            {
                //data = db.Users.Where(x => x.IsVerified == true && x.RoleId == 2 && x.Id == Id).OrderByDescending(x => x.Id).FirstOrDefault().RemoveRefernces();
                data = db.Users.Where(x => x.IsActive == true && x.RoleId == 2 && x.Id == Id).Include(x => x.Company).OrderByDescending(x => x.Id).FirstOrDefault();

                model.Id          = data.Id;
                model.FirstName   = data.FirstName;
                model.MiddleName  = data.MiddleName;
                model.LastName    = data.LastName;
                model.Company     = data.Company?.Name;
                model.DisplayName = data.DisplayName;
                model.UserName    = data.UserName;
                model.Email       = data.Email;
                model.Phone       = data.Phone;
                model.DOB         = data.DOB;
                model.Address     = data.Address;
                model.CountryId   = data.CountryId;
                model.CompanyId   = data.CompanyId;
                model.StateId     = data.StateId;
                model.City        = data.City;
                model.PostalCode  = data.PostalCode;
                model.LanguageId  = data.LanguageId;
                model.GenderId    = data.GenderId;
                model.FacebookId  = data.FacebookId;
                model.TwitterId   = data.TwitterId;
                model.Image       = data.Image;
                model.Logo        = data.Company?.Logo;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            return(Ok(model));
        }
Beispiel #5
0
        public async Task <RegisterVendorResponse> RegisterVendor(RegisterVendor registerVenderModel)
        {
            RegisterVendorResponse registerVendorResponse = new RegisterVendorResponse();

            List <SqlParameter> sqlParameters = new List <SqlParameter>()
            {
                new SqlParameter("VendorName", registerVenderModel.VendorName),
                new SqlParameter("VendorEmail", registerVenderModel.VendorEmail),
                new SqlParameter("IsBranch", false),
                new SqlParameter("Mobile", registerVenderModel.VendorMobile),
                new SqlParameter("Landline", registerVenderModel.VendorLandline),
                new SqlParameter("AddressLine", registerVenderModel.AddressLine),
                new SqlParameter("City", registerVenderModel.City),
                new SqlParameter("State", registerVenderModel.State),
                new SqlParameter("PinCode", registerVenderModel.PinCode)
            };

            SqlParameter[] outputParameter =
            {
                new SqlParameter("IsUserExists", SqlDbType.Bit),
                new SqlParameter("Success",      SqlDbType.Bit),
            };

            var result = _databaseContext.Repository <Task>().ExecuteSp(StoreProcedureSchemas.usp_RegisterVendor, sqlParameters.ToArray(), outputParameter);

            registerVendorResponse.IsUserExists = Convert.ToBoolean(result.OutParam[0].Value);
            registerVendorResponse.Success      = Convert.ToBoolean(result.OutParam[1].Value);
            registerVendorResponse.Content      =
                result.Data.AsEnumerable().Select(dataRow => new VendorDetails
            {
                VendorId    = dataRow.Field <int>("VendorId"),
                VendorName  = dataRow.Field <string>("VendorName"),
                VendorEmail = dataRow.Field <string>("VendorEmail"),
                Mobile      = dataRow.Field <string>("Mobile"),
                Landline    = dataRow.Field <string>("Landline"),
            }).FirstOrDefault();

            return(await Task.FromResult(registerVendorResponse));
        }
Beispiel #6
0
        public async Task <User> RegisterVendor(RegisterVendor model)
        {
            JsonResult response      = null;
            var        user          = new User();
            var        salt          = CommonFunctions.CreateSalt(64); //Generate a cryptographic random number.
            var        hashAlgorithm = new SHA512HashAlgorithm();
            var        data          = db.Users.Where(x => (x.Email == model.Email || x.Company.Name == model.Company) && x.IsActive == true && x.RoleId == 2).Include(x => x.Company).FirstOrDefault();

            if (data == null)
            {
                try {
                    //state
                    var states = db.States.Where(x => x.IsActive == true).ToList();
                    if (model.State != null)
                    {
                        var state = states.Where(x => x.Name.ToLower().Trim().Equals(model.State.ToLower().Trim())).FirstOrDefault();
                        if (state != null)
                        {
                            model.StateId = state.Id;
                        }
                        else
                        {
                            var enter = new State();
                            enter.IsActive  = true;
                            enter.Name      = model.State;
                            enter.CountryId = Convert.ToInt32(model.CountryId);
                            db.States.Add(enter);
                            db.SaveChanges();
                            model.StateId = enter.Id;
                        }
                    }
                    user = new User()
                    {
                        FirstName    = model.FirstName,
                        MiddleName   = model.MiddleName,
                        LastName     = model.LastName,
                        DisplayName  = model.DisplayName,
                        UserName     = model.UserName,
                        Address      = model.Address,
                        City         = model.City,
                        CountryId    = model.CountryId,
                        StateId      = model.StateId,
                        Email        = model.Email,
                        Phone        = model.Phone,
                        PasswordHash = hashAlgorithm.GenerateSaltedHash(CommonFunctions.GetBytes(model.Password), salt),
                        PasswordSalt = salt,
                        RoleId       = 2,
                        IsVerified   = true,
                        IsActive     = true,
                        FacebookId   = model.FacebookId,
                        TwitterId    = model.TwitterId,
                        GenderId     = model.GenderId,
                        LanguageId   = model.LanguageId,
                        PostalCode   = model.PostalCode,
                        DOB          = model.DOB,
                        VendorId     = "Pistis_sno_" + model.Company,
                        RFC          = model.RFC
                    };
                    if (model.Image != null && model.Image != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.Image);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            user.Image = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                        }
                    }
                    var com = new Company();
                    if (model.Logo != null && model.Logo != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.Logo);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            com.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                        }
                    }
                    com.IsActive = true;
                    com.Name     = model.Company;
                    db.Companies.Add(com);
                    db.SaveChanges();
                    user.CompanyId = com.Id;
                    db.Users.Add(user);
                    db.SaveChanges();

                    var proof = new Models.VendorIDProof();
                    if (model.IdProof != null && model.IdProof != "")
                    {
                        var imageResponse = await S3Service.UploadObject(model.IdProof);

                        response = new JsonResult(new object());
                        if (imageResponse.Success)
                        {
                            proof.Proof    = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                            proof.UserId   = user.Id;
                            proof.IsActive = true;
                            db.VendorIDProof.Add(proof);
                            db.SaveChanges();
                        }
                    }
                    //email
                    if (user.Id != 0)
                    {
                        MailAddress objFrom = new MailAddress(_settings.Value.ADMINEMAIL, "info@eschedule");
                        MailMessage mailMsg = new MailMessage();
                        mailMsg.From = objFrom;
                        var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/vendorRegister.html");

                        html = html.Replace("{{userName}}", user.FirstName);
                        Emailmodel emailmodel = new Emailmodel();
                        emailmodel.From    = "";
                        emailmodel.To      = user.Email;
                        emailmodel.Subject = " Congratulations, Registered Successfully";
                        emailmodel.Body    = html;
                        emailmodel.key     = "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";
                        await Example.Execute(emailmodel);
                    }

                    var result = new User();
                    result.ReturnCode    = 0;
                    result.ReturnMessage = "You are registered successfully";
                    return(result);
                }
                catch (Exception ex)
                {
                    user.ReturnCode    = -1;
                    user.ReturnMessage = ex.Message;
                    return(user);
                }
            }
            else
            {
                user.ReturnCode = -1;
                if (data.Email == model.Email)
                {
                    user.ReturnMessage = "Email is already registered";
                }
                else if (data.Company.Name == model.Company)
                {
                    user.ReturnMessage = "Company is already registered";
                }
                else
                {
                    user.ReturnMessage = "Something went Wrong";
                }
                return(user);
            }
        }
Beispiel #7
0
        public async Task <RegisterVendor> updateVendor(RegisterVendor user)
        {
            var getCompany = db.Companies.Where(x => x.Name.ToLower().Trim() == user.Company.ToLower().Trim()).FirstOrDefault();
            var obj        = db.Users.Where(x => x.IsActive == true && x.RoleId == 2 && x.Id == user.Id).Include(x => x.Company).FirstOrDefault();

            if (obj.Company != null)
            {
                var com = db.Companies.Where(x => x.Id == obj.CompanyId).FirstOrDefault();
            }
            //else
            //{
            //    getCompany = new Company();
            //    getCompany.Name = user.Company;
            //    JsonResult response1 = null;

            //    if (user.Logo != null)//if new image
            //    {
            //        var imageResponse1 = await S3Service.UploadObject(user.Logo);
            //        response1 = new JsonResult(new object());

            //        if (imageResponse1.Success)
            //            user.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse1.FileName}";
            //    }
            //    getCompany.Logo = user.Logo;
            //    getCompany.IsActive = true;
            //    db.Companies.Add(getCompany);
            //    db.SaveChanges();
            //}
            if (getCompany == null)
            {
                getCompany      = new Company();
                getCompany.Name = user.Company;
                JsonResult response1 = null;

                if (user.Logo != null)//if new image
                {
                    var imageResponse1 = await S3Service.UploadObject(user.Logo);

                    response1 = new JsonResult(new object());

                    if (imageResponse1.Success)
                    {
                        user.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse1.FileName}";
                    }
                }
                getCompany.Logo     = user.Logo;
                getCompany.IsActive = true;
                db.Companies.Add(getCompany);
                db.SaveChanges();
            }

            JsonResult response = null;

            try
            {
                if (user != null)
                {
                    obj.Address     = user.Address;
                    obj.Email       = user.Email;
                    obj.Phone       = user.Phone;
                    obj.StateId     = user.StateId;
                    obj.CountryId   = user.CountryId;
                    obj.DOB         = user.DOB;
                    obj.City        = user.City;
                    obj.LanguageId  = user.LanguageId;
                    obj.GenderId    = user.GenderId;
                    obj.TwitterId   = user.TwitterId;
                    obj.FacebookId  = user.FacebookId;
                    obj.PostalCode  = user.PostalCode;
                    obj.FirstName   = user.FirstName;
                    obj.LastName    = user.LastName;
                    obj.DisplayName = user.DisplayName;
                    obj.UserName    = user.UserName;
                    obj.MiddleName  = user.MiddleName;
                    obj.IsActive    = true;
                    obj.IsVerified  = true;
                    if (obj.Company == null)
                    {
                        obj.CompanyId = getCompany.Id;
                    }

                    if (user.Image != null && !(user.Image.StartsWith("http")))//if new image
                    {
                        var imageResponse = await S3Service.UploadObject(user.Image);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            obj.Image = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                        }
                    }
                    else
                    {
                        obj.Image = user.Image ?? null;
                    }

                    if (user.Logo != null && !(user.Logo.StartsWith("http")))//if new logo
                    {
                        var imageResponse = await S3Service.UploadObject(user.Logo);

                        response = new JsonResult(new object());

                        if (imageResponse.Success)
                        {
                            if (obj.Company != null)
                            {
                                obj.Company.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                            }
                            else
                            {
                                getCompany.Logo = $"https://pistis.s3.us-east-2.amazonaws.com/{imageResponse.FileName}";
                            }
                        }
                        db.SaveChanges();
                    }
                    //  else obj.Company.Logo = user.Logo ?? null;

                    //  obj.Company.Name = user.Company ?? null;

                    // db.Entry(obj).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
            return(user);
        }