Beispiel #1
0
        public bool AddUser(Admin admin, User user)
        {
            if (user == null) throw new Exception(ErrorConstants.REQUIRED_FIELD_EMPTY);
            if (admin == null || admin.type != (int)BillingEnums.USER_TYPE.ADMIN) throw new Exception(ErrorConstants.NO_PREVILAGE);

            try
            {
                var elasticClient = GetElasticClient();

                var userExist = GetUserById(admin, user.userid);
                if (userExist != null) throw new Exception(ErrorConstants.USER_WITH_GIVEN_ID_ALREADY_EXIST);

                var response = elasticClient.Index<User>(user, i => i
                 .Index(ElasticMappingConstants.INDEX_NAME)
                 .Type(ElasticMappingConstants.TYPE_USER)
                );

                return response.RequestInformation.Success;
            }
            catch (Exception e)
            {

                throw e;
            }
        }
Beispiel #2
0
        public JsonResult UpdateUser()
        {
            var id = Request.Params.Get(AppConstants.USER_ID);
            var name = Request.Params.Get(AppConstants.NAME);
            var addr1 = Request.Params.Get(AppConstants.ADDRESS_1);
            var addr2 = Request.Params.Get(AppConstants.ADDRESS_2);
            var city = Request.Params.Get(AppConstants.CITY);
            var district = Request.Params.Get(AppConstants.DISTRICT);
            var state = Request.Params.Get(AppConstants.START);
            var country = Request.Params.Get(AppConstants.COUNTRY);
            var phone = Request.Params.Get(AppConstants.PHONE);
            var pinCode = Request.Params.Get(AppConstants.PIN_CODE);
            var email = Request.Params.Get(AppConstants.EMAIL);

            var response = new ServiceResponse();

            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(name) && String.IsNullOrWhiteSpace(addr1) && String.IsNullOrWhiteSpace(addr2) && String.IsNullOrWhiteSpace(city) && String.IsNullOrWhiteSpace(district) && String.IsNullOrWhiteSpace(state) && String.IsNullOrWhiteSpace(country) && String.IsNullOrWhiteSpace(pinCode) && String.IsNullOrWhiteSpace(phone) && String.IsNullOrWhiteSpace(email))
            {
                response.result = ErrorConstants.NO_CHANGES;
                return Json(response);
            }

            try
            {
                var user = new User()
                {
                    userid = id,
                    name = name,
                    addr1 = addr1,
                    addr2 = addr2,
                    city = city,
                    district = district,
                    state = state,
                    country = country,
                    pincode = pinCode,
                    phone = phone,
                    email = email,
                };

                if (userManager.UpdateUser(admin, user))
                {
                    response.result = SuccessConstants.USER_UPDATED;
                    response.status = true;
                }
                else
                    response.result = ErrorConstants.PROBLEM_UPDATING_USER;

                return Json(response);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }
Beispiel #3
0
        public bool  UpdateUser(Admin admin, User user)
        {
            if (user == null) throw new Exception(ErrorConstants.REQUIRED_FIELD_EMPTY);
            if (admin == null || admin.type != (int)BillingEnums.USER_TYPE.ADMIN) throw new Exception(ErrorConstants.NO_PREVILAGE);

            try
            {
                var userElasticId = GetUserId(user.userid);
                if (String.IsNullOrWhiteSpace(userElasticId)) throw new Exception(ErrorConstants.USER_NOT_FOUND);

                var userUpdate = new Dictionary<string, object>();

                if (!String.IsNullOrWhiteSpace(user.name))
                    userUpdate[ConstUser.NAME] = user.name;
                if (!String.IsNullOrWhiteSpace(user.addr1))
                    userUpdate[ConstUser.ADDR_1] = user.addr1;
                if (!String.IsNullOrWhiteSpace(user.addr2))
                    userUpdate[ConstUser.ADDR_2] = user.addr2;
                if (!String.IsNullOrWhiteSpace(user.city))
                    userUpdate[ConstUser.CITY] = user.city;
                if (!String.IsNullOrWhiteSpace(user.district))
                    userUpdate[ConstUser.DISTRICT] = user.district;
                if (!String.IsNullOrWhiteSpace(user.state))
                    userUpdate[ConstUser.STATE] = user.state;
                if (!String.IsNullOrWhiteSpace(user.country))
                    userUpdate[ConstUser.COUNTRY] = user.country;
                if (!String.IsNullOrWhiteSpace(user.pincode))
                    userUpdate[ConstUser.PIN_CODE] = user.pincode;
                if (!String.IsNullOrWhiteSpace(user.phone))
                    userUpdate[ConstUser.PHONE] = user.phone;
                if (!String.IsNullOrWhiteSpace(user.email))
                    userUpdate[ConstUser.EMAIL] = user.email;

                var elasticClient = GetElasticClient();

                var response = elasticClient.Update<User, object>(u => u
                .Index(ElasticMappingConstants.INDEX_NAME)
                .Type(ElasticMappingConstants.TYPE_USER)
                .Id(userElasticId)
                .Doc(userUpdate)
                );

                return response.RequestInformation.Success;
            }
            catch (Exception e)
            {

                throw e;
            }
        }