Exemple #1
0
        public async Task <FAQ> AddFAQ(string question, string answer)
        {
            if (question == null || question == "")
            {
                throw new Exception($"Question is required. Please write a question.");
            }
            if (answer == null || answer == "")
            {
                throw new Exception($"Answer is required. Please write an answer.");
            }

            if (await IsQuestionDuplicate(question))
            {
                throw new Exception($"'{question}' already exists. Please choose a different question.");
            }

            FAQ faq = new FAQ
            {
                Question = question,
                Answer   = answer
            };
            await _dbContext.FAQs.AddAsync(faq);

            await _dbContext.SaveChangesAsync();

            return(faq);
        }
Exemple #2
0
        public async Task <Claim> AddClaim(int claimNo, string description)
        {
            if (claimNo == 0)
            {
                throw new Exception($"Claim is required. Please write a claim no.");
            }
            if (description == null || description == "")
            {
                throw new Exception($"Description is required. Please write a description.");
            }

            if (await IsNameDuplicate(claimNo))
            {
                throw new Exception($"'{claimNo}' already exists. Please choose a different claim number.");
            }

            Claim claim = new Claim
            {
                ClaimNo     = claimNo,
                Description = description
            };
            await _dbContext.Claims.AddAsync(claim);

            await _dbContext.SaveChangesAsync();

            return(claim);
        }
Exemple #3
0
        public async Task <HttpResponseMessage> DeleteCopyrightOfUser(Guid copyrightId, Guid userId)
        {
            HttpResponseMessage responseMessage = new HttpResponseMessage();
            var copyright = await _dbContext.UsersIps
                            .Where(x => x.UserId == userId && x.Id == copyrightId && x.IpType == IpType.Copyright && x.IsActive).FirstOrDefaultAsync();

            if (copyright != null)
            {
                copyright.IsActive = false;
                await _dbContext.SaveChangesAsync();

                responseMessage.StatusCode = HttpStatusCode.OK;
                responseMessage.Content    = new StringContent("Success: " + copyright.Title + "deleted successfully.");
            }
            else
            {
                responseMessage.StatusCode = HttpStatusCode.NotFound;
                responseMessage.Content    = new StringContent("Not Found: This title ia already taken!");
            }
            return(responseMessage);
        }
Exemple #4
0
        //sign up for user
        public async Task <User> SignUp(UserModel userModel)
        {
            User user = new User
            {
                FirstName  = userModel.FirstName,
                LastName   = userModel.LastName,
                Contact    = userModel.Contact,
                Cnic       = userModel.Cnic,
                Email      = userModel.Email,
                Password   = userModel.Password,
                ImagePath  = "Placeholder.jpg",
                RoleId     = 1,
                CreatedAt  = DateTime.Now,
                LastModify = DateTime.Now,
                IsActive   = true,
                ResetCode  = Convert.ToInt64("")
            };
            var emailExist = await ExitingEmail(user.Email);

            var usernameExist = await ExistingUsername(user.FirstName, user.LastName);

            var contactExist = await ExistingContact(user.Contact);

            if (emailExist || usernameExist || contactExist)
            {
                return(user = null);
            }
            else
            {
                _dbContext.Users.Add(user);
                await _dbContext.SaveChangesAsync();

                return(user);
            }
        }
Exemple #5
0
        public async Task <City> AddCity(string cityName)
        {
            if (cityName == null || cityName == "")
            {
                throw new Exception($"CityName is required. Please write a name.");
            }

            if (await IsNameDuplicate(cityName))
            {
                throw new Exception($"'{cityName}' already exists. Please choose a different name.");
            }

            City city = new City
            {
                CityName = cityName
            };
            await _dbContext.Cities.AddAsync(city);

            await _dbContext.SaveChangesAsync();

            return(city);
        }
Exemple #6
0
        public async Task <IpFilter> AddCategory(string name)
        {
            if (await IsCategoryDuplicate(name))
            {
                throw new Exception($"'{name}' already exists. Please choose a different name.");
            }
            IpFilter maxRecord = await _dbContext.IpFilters.OrderByDescending(x => x.Id).FirstOrDefaultAsync();

            var      maxId    = maxRecord.Id;
            IpFilter category = new IpFilter
            {
                Name = name,
                Type = FilterType.Category,
                Code = "Cat-" + maxId
            };
            await _dbContext.IpFilters.AddAsync(category);

            await _dbContext.SaveChangesAsync();

            return(category);
        }
Exemple #7
0
        public async Task <User> SignUp(User user)
        {
            CheckNullOrEmpty(user);
            if (await IsUsernameDuplicate(user.FirstName, user.LastName))
            {
                throw new Exception($"'{user.FirstName}'+ '{user.LastName}' already exists. Please choose a different name.");
            }
            if (await IsContactDuplicate(user.Contact))
            {
                throw new Exception($"'{user.Contact}' already exists. Please choose a different contact no.");
            }
            if (await IsEmailDuplicate(user.Email))
            {
                throw new Exception($"'{user.Email}' already exists. Please choose a different email.");
            }
            if (await IsCnicDuplicate(user.Cnic))
            {
                throw new Exception($"'{user.Cnic}' already exists. Please choose a different cnic.");
            }

            int generateOTP = await GenerateOTP();

            string encodedPassword = await EncodePasswordToBase64(user.Password);

            user.RoleId     = 1;
            user.OTP        = generateOTP;
            user.Password   = encodedPassword;
            user.ImagePath  = "Placeholder.png";
            user.CreatedAt  = DateTime.Now;
            user.LastModify = DateTime.Now;
            user.IsActive   = true;
            await _dbContext.Users.AddAsync(user);

            await _dbContext.SaveChangesAsync();

            return(user);
        }
Exemple #8
0
        public async Task <UsersIp> DeleteCopyright(Guid userId, Guid id)
        {
            var copyright = await GetCopyrightById(userId, id);

            _dbContext.Remove(copyright);
            await _dbContext.SaveChangesAsync();

            return(copyright);
        }