public DataResponse <EntityBusinessMaster> UpdateBusiness(EntityBusinessMaster entity)
        {
            var response = new DataResponse <EntityBusinessMaster>();

            try
            {
                base.DBInit();

                var model = DBEntity.BusinessMasters.FirstOrDefault(a => a.Id == entity.Id);
                model.BusinessName = entity.BusinessName;
                model.Description  = entity.Description;
                model.IsActive     = entity.IsActive;
                model.UpdatedOn    = entity.UpdatedOn;
                model.UpdatedBy    = entity.UpdatedBy;

                if (base.DBSaveUpdate(model) > 0)
                {
                    return(GetBusinessById(model.Id));
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
Beispiel #2
0
        public IHttpActionResult UpdateBusiness(int id, BusinessMasterModel model)
        {
            var response = new DataResponse <EntityBusinessMaster>();

            if (ModelState.IsValid)
            {
                var entityBusinessProfile = new EntityBusinessMaster();
                entityBusinessProfile.Id           = id;
                entityBusinessProfile.BusinessName = model.BusinessName;
                entityBusinessProfile.Description  = model.Description;
                entityBusinessProfile.UpdatedBy    = 1;
                entityBusinessProfile.IsActive     = model.IsActive;
                entityBusinessProfile.UpdatedOn    = System.DateTime.UtcNow;
                response = repository.UpdateBusiness(entityBusinessProfile);
            }

            return(Ok <DataResponse>(response));
        }
        public DataResponse <EntityBusinessMaster> Insert(EntityBusinessMaster entity)
        {
            var response = new DataResponse <EntityBusinessMaster>();

            try
            {
                base.DBInit();

                var model = new Database.BusinessMaster
                {
                    BusinessName = entity.BusinessName,
                    RelativeUrl  = entity.BusinessName.ToLower().Replace(" ", "-"),
                    Description  = entity.Description,
                    CreatedBy    = 1,
                    CreatedOn    = System.DateTime.UtcNow,
                    IsActive     = true,
                    Status       = 1
                };

                if (base.DBSave(model) > 0)
                {
                    entity.Id = model.Id;
                    response.CreateResponse <EntityBusinessMaster>(entity, DataResponseStatus.OK);
                    return(response);
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
            }
            finally
            {
                base.DBClose();
            }
            return(response);
        }
Beispiel #4
0
        public async Task <IHttpActionResult> CreateBusiness(BusinessMasterModel model)
        {
            var response = new DataResponse <EntityBusinessMaster>();

            var userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <GMUserManager>();
            var roleManager = System.Web.HttpContext.Current.GetOwinContext().Get <GMRoleManager>();

            if (ModelState.IsValid)
            {
                if (db.BusinessMasters.Any(a => a.BusinessName.ToLower() == model.BusinessName.ToLower()))
                {
                    var error = string.Format("{0} is already used.", model.BusinessName);
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = error }));
                }

                model.Password = GeneralHelpers.GeneratePassword(3, 2, 2);
                var user = new GMUser
                {
                    FirstName   = model.FirstName,
                    MiddleName  = model.MiddleName,
                    LastName    = model.LastName,
                    PhoneNumber = model.PhoneNumber,
                    UserName    = model.Email,
                    Email       = model.Email,
                    IsActive    = true,
                };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var roleName = "BusinessAdmin";
                    var role     = roleManager.FindByName(roleName);
                    if (role == null)
                    {
                        db.Roles.Add(new Role {
                            Name = roleName, Description = roleName, IsActive = true, CreatedBy = 1, CreatedOn = System.DateTime.UtcNow
                        });
                        db.SaveChanges();
                    }
                    UserManager.AddToRolesAsync(user.Id, roleName);
                }
                else
                {
                    var error = string.Format("{0} is already used.", model.Email);
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = error }));
                }

                var entityBusinessProfile = new EntityBusinessMaster();
                entityBusinessProfile.BusinessName = model.BusinessName;
                entityBusinessProfile.RelativeUrl  = model.BusinessName.ToLower().Replace(" ", "-");
                entityBusinessProfile.Description  = model.Description;
                entityBusinessProfile.CreatedBy    = 1;
                response = repository.Insert(entityBusinessProfile);

                if (response.Model.Id > 0)
                {
                    var userDetails = db.Users.FirstOrDefault(a => a.Id == user.Id);
                    userDetails.UserProfiles.Add(new UserProfile {
                        CreatedBy = 1, CreatedOn = DateTime.UtcNow, UserId = userDetails.Id
                    });
                    userDetails.BusinessId = response.Model.Id;
                    db.SaveChanges();

                    model.RootPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                    string ReturnUrl = ConfigurationManager.AppSettings["BaseUrl"];
                    ReturnUrl = ReturnUrl + model.BusinessName.Replace(" ", "-");
                    string RelativeUrl = model.BusinessName.ToLower().Replace(" ", "-");

                    string managerEmailBody = string.Empty;
                    var    mail             = new GMEmail();
                    managerEmailBody = TemplateManager.NewBusinessCreate(model.RootPath, model.BusinessName, user.UserName, model.Password, model.FirstName, ReturnUrl, response.Model.Id, RelativeUrl);
                    mail.SendDynamicHTMLEmail(model.Email, "New Business Created", managerEmailBody, CurrentUser.OtherEmails);

                    //string rootPath = ConfigurationManager.AppSettings["FolderPath"];
                    string        rootPath = HttpContext.Current.Server.MapPath("~/Assets");
                    string        path     = Path.Combine(rootPath, response.Model.Id.ToString());
                    DirectoryInfo dir      = new DirectoryInfo(path);
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                }
            }

            return(Ok <DataResponse>(response));
        }