Esempio n. 1
0
        /// <summary>
        /// Create Country
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task <string> CreateCountry(CountryDTO obj)
        {
            string status = "";

            try
            {
                //Check if Countrycode, NAME AND Nationality exist
                var checkexist = await _context.BtCountry
                                 .AnyAsync(x => x.CountryCode == obj.countrycode ||
                                           x.Name == obj.name || x.Nationality == obj.nationality);

                if (checkexist == false)
                {
                    BtCountry newrecord = new BtCountry
                    {
                        CountryCode      = obj.countrycode,
                        Name             = obj.name,
                        NationalCurrency = obj.nationalcurrency,
                        Nationality      = obj.nationality,
                        CreatedBy        = _authUser.Name,
                        CreatedDate      = DateTime.Now,
                        IsActive         = true,
                        LastModified     = null,
                        ModifiedBy       = null
                    };

                    _context.BtCountry.Add(newrecord);
                    if (await _context.SaveChangesAsync() > 0)
                    {
                        status = "1";

                        return(status);
                    }
                    else
                    {
                        status = ResponseErrorMessageUtility.RecordNotSaved;
                        return(status);
                    }
                }
                status = string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.name);
                return(status);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                status = ResponseErrorMessageUtility.RecordNotSaved;
                return(status);
            }
        }
        public async Task CreateLastLoginDate(string userid)
        {
            try
            {
                var checkexits = await _context.Users.FirstOrDefaultAsync(x => x.Id == userid);

                checkexits.LastLoginDate = DateTime.Now;
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }
Esempio n. 3
0
        public async Task <string> CreateEmailTemplate(EmailTemplateDTO obj)
        {
            string status = "";

            try
            {
                var checkexist = await _context.TEmailtemplate
                                 .AnyAsync(x => x.Name == obj.name || x.Code == obj.code);

                if (checkexist == false)
                {
                    TEmailtemplate newrecord = new TEmailtemplate
                    {
                        Name         = obj.name,
                        Body         = obj.body,
                        Code         = obj.code,
                        Subject      = obj.subject,
                        CreatedBy    = _authUser.Name,
                        CreatedDate  = DateTime.Now,
                        IsActive     = true,
                        LastModified = null,
                        ModifiedBy   = null
                    };

                    _context.TEmailtemplate.Add(newrecord);
                    if (await _context.SaveChangesAsync() > 0)
                    {
                        status = "1";
                        return(status);
                    }
                    else
                    {
                        status = ResponseErrorMessageUtility.RecordNotSaved;
                        return(status);
                    }
                }
                status = string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.name);
                return(status);
            }

            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                status = ResponseErrorMessageUtility.RecordNotSaved;
                return(status);
            }
        }
        public async Task <string> UpdateMyProfileAsync(UserViewModel obj)
        {
            try
            {
                var checkuser = await _context.Users.FirstOrDefaultAsync(x => x.Id != _authUser.UserId);

                if (checkuser.Email == obj.email)
                {
                    return(string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.email));
                }

                if (checkuser.PhoneNumber == obj.phonenumber)
                {
                    return(string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.phonenumber));
                }

                //var fetchdata = await _context.TUserExt.FirstOrDefaultAsync(x => x.GsuserId == _authUser.UserId);
                var fetchuser = await _context.Users.FirstOrDefaultAsync(x => x.Id == _authUser.UserId);

                fetchuser.Email           = obj.email;
                fetchuser.NormalizedEmail = obj.email.ToUpper();
                fetchuser.PhoneNumber     = obj.phonenumber;
                //fetchdata.Firstname = obj.firstname;
                //fetchdata.LastModified = DateTime.Now;
                //fetchdata.Lastname = obj.lastname;
                //fetchdata.Middlename = obj.middlename;
                //fetchdata.ModifiedBy = _authUser.Name;
                if (await _context.SaveChangesAsync() > 0)
                {
                    return("1");
                }
                return(ResponseErrorMessageUtility.RecordNotSaved);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw;
            }
        }
        public async Task <string> CreateRegulator(RegulatorDTO obj)
        {
            string status = "";

            try
            {
                //Fetch all permissions
                var fetchallpermissions = Enum.GetValues(typeof(myFacilityPermissions)).Cast <myFacilityPermissions>()
                                          .ToList();
                //Check if Course and Description exist
                var checkexist = await _context.TRegulator.AnyAsync(x => x.Name == obj.name);

                if (checkexist == false)
                {
                    TRegulator newrecord = new TRegulator
                    {
                        Name         = obj.name,
                        Address      = obj.address,
                        Email        = obj.email,
                        RegCode      = obj.regcode,
                        CreatedBy    = _authUser.Name,
                        CreatedDate  = DateTime.Now,
                        IsActive     = true,
                        LastModified = null,
                        ModifiedBy   = null
                    };

                    _context.TRegulator.Add(newrecord);
                    if (await _context.SaveChangesAsync() > 0)
                    {
                        BtPermissions btPermissions = new BtPermissions
                        {
                            PermissionId = Guid.NewGuid().ToString(),
                            Permissions  = fetchallpermissions.Where(x => x != myFacilityPermissions.AccessAll &&
                                                                     x != myFacilityPermissions.NotSet).PackPermissionsIntoString(),
                            IsActive     = true,
                            RegId        = newrecord.RegId,
                            CreatedBy    = _authUser.Name,
                            CreatedDate  = DateTime.Now,
                            ModifiedBy   = null,
                            LastModified = null
                        };

                        _context.BtPermissions.Add(btPermissions);
                        await _context.SaveChangesAsync();

                        status = "1";
                        return(status);
                    }
                    else
                    {
                        status = ResponseErrorMessageUtility.RecordNotSaved;
                        return(status);
                    }
                }
                status = string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.name);
                return(status);
            }

            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                status = ResponseErrorMessageUtility.RecordNotSaved;
                return(status);
            }
        }