Esempio n. 1
0
        /// <summary>
        /// Update State Record
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <string> UpdateLga(LgaDTO obj, int id)
        {
            string status = "";

            try
            {
                //Check if record exist not as same id
                var checkexist = await _context.BtState.AnyAsync(x => x.StateId != id && (x.Name == obj.name));

                if (checkexist == false)
                {
                    var state = await _context.BtState.FirstOrDefaultAsync(x => x.StateId == id);

                    state.Name = obj.name;

                    //state.CountryCode = obj.countrycode;
                    state.ModifiedBy   = _authUser.Name;
                    state.LastModified = DateTime.Now;
                    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);
            }
        }
Esempio n. 2
0
        public async Task <string> CreateLga(LgaDTO obj)
        {
            string status = "";

            try
            {
                //Check Country
                var checkcountry = await _context.BtLga.AsNoTracking().FirstOrDefaultAsync(x => x.StateCode == obj.statecode);

                if (checkcountry == null)
                {
                    status = "The state code is not valid.";
                    return(status);
                }

                //Check Country
                var checkstate = await _context.BtLga.AsNoTracking()
                                 .FirstOrDefaultAsync(x => x.Name == obj.name && x.StateCode == checkcountry.StateCode);

                if (checkstate != null)
                {
                    status = string.Format(ResponseErrorMessageUtility.RecordExistBefore, obj.name);
                    return(status);
                }

                //Assign State Code
                var getstate = await _context.BtLga.AsNoTracking()
                               .Where(x => x.StateCode == checkcountry.StateCode && !x.StateCode.Contains("N/A"))
                               .Select(x => int.Parse(x.StateCode)).ToListAsync();

                var getLastID = (getstate.Count() > 0) ? getstate.Max() : 0;



                BtLga newrecord = new BtLga
                {
                    Name         = obj.name,
                    LgaCode      = Convert.ToString(getLastID + 1),
                    StateCode    = checkcountry.StateCode,
                    CreatedBy    = _authUser.Name,
                    CreatedDate  = DateTime.Now,
                    IsActive     = true,
                    LastModified = null,
                    ModifiedBy   = null
                };
                _context.BtLga.Add(newrecord);
                if (await _context.SaveChangesAsync() > 0)
                {
                    status = "1";

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