Exemple #1
0
        public Responce <bool> UpdateUserRole(UpdateUserRoleRequest request)
        {
            Responce <bool> responce = new Responce <bool>();

            responce.Success = true;

            try
            {
                responce.Success = true;
                using (SSCEntities db = new SSCEntities())
                {
                    db.UpdateUserRole(request.RoleId, request.UserId);
                    responce.ResponeContent = true;
                }
            }
            catch (Exception ex)
            {
                responce.Success        = false;
                responce.Message        = $"ERROR UpdateUserRole : {ex.InnerException}";
                responce.ResponeContent = false;
            }
            return(responce);
        }
Exemple #2
0
        public async Task <IHttpActionResult> CreateCity(CityDTO citydto)
        {
            Responce <bool> responce = new Responce <bool>();

            try
            {
                var IsUserExist = await UserManager.FindByNameAsync(citydto.AdminEmail);

                if (IsUserExist != null)
                {
                    var Errors = "User email already registered.";
                    responce.Fail(Errors);
                    responce.ResponeContent = false;
                    return(Content(HttpStatusCode.BadRequest, responce));
                }

                using (var db = new SSCEntities())
                {
                    var CheckCity = db.Citys.Where(a => a.CityName.ToLower() == citydto.CityName.ToLower())?.ToList() ?? new List <Citys>();
                    if (CheckCity.Count > 0)
                    {
                        responce.ResponeContent = false;
                        responce.Success        = false;
                        responce.Message        = "City already added";
                        return(Content(HttpStatusCode.BadRequest, responce));
                    }

                    DateTime dateTime = DateTime.UtcNow;

                    Citys citys = new Citys();
                    citys.MCEmail         = citydto.MCEmail;
                    citys.FcciEmail       = citydto.FcciEmail;
                    citys.CityName        = citydto.CityName;
                    citys.IsActive        = citydto.IsActive;
                    citys.AdminEmail      = citydto.AdminEmail;
                    citys.CreatedBy       = citydto.CreatedBy;
                    citys.CreatedDate     = dateTime;
                    citys.ModifiedBy      = citydto.ModifiedBy;
                    citys.ModifiedDate    = dateTime;
                    db.Entry(citys).State = System.Data.Entity.EntityState.Added;
                    await db.SaveChangesAsync();

                    var         lows        = db.Lows.ToList();
                    SSCEntities sscEntities = new SSCEntities();
                    foreach (var item in lows)
                    {
                        CityLows cityLows = new CityLows();
                        cityLows.Id    = citys.Id;
                        cityLows.LowId = item.Id;
                        sscEntities.Entry(cityLows).State = System.Data.Entity.EntityState.Added;
                        await sscEntities.SaveChangesAsync();
                    }

                    var user = new ApplicationUser()
                    {
                        UserName = citydto.AdminEmail, Email = citydto.AdminEmail, City = citydto.CityName, PhoneNumber = citydto.MobileNo, Name = citydto.UserName, IsDefaultAdmin = true, CityId = citys.Id
                    };

                    IdentityResult result = await UserManager.CreateAsync(user, citydto.Password);

                    if (!result.Succeeded)
                    {
                        var Errors = GetIdentityErrorResult(result);
                        responce.Fail(Errors);
                        responce.ResponeContent = false;

                        return(Content(HttpStatusCode.BadRequest, responce));
                    }

                    db.UpdateUserRole("989D2937-0FC5-497D-980C-B2E8583602B9", user.Id);
                    responce.ResponeContent = true;

                    responce.Success = true;
                }


                return(Ok(responce));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }