Example #1
0
        public async Task <ReturnResponse <ResponseDetail> > AddRegion(string region)
        {
            try
            {
                if (!await _context.Region.AnyAsync(x => x.Name.ToLower() == region.ToLower()))
                {
                    await _context.Region.AddAsync(new Region
                    {
                        Name = region
                    });

                    if (await _context.SaveChangesAsync() == 1)
                    {
                        return(GlobalReturnService.ResponseData(HttpStatusCode.OK, "Success",
                                                                true));
                    }
                    return(GlobalReturnService.ResponseData(HttpStatusCode.InternalServerError, "Something Went Wrong, while updating entries",
                                                            false));
                }
                else
                {
                    return(GlobalReturnService.ResponseData(HttpStatusCode.Conflict, "region already Exist",
                                                            false));
                }
            }
            catch (Exception e)
            {
                return(GlobalReturnService.ResponseData(HttpStatusCode.InternalServerError, "Something Went Wrong, please contact admin",
                                                        false));
            }
        }
Example #2
0
        public async Task <ReturnResponse <ResponseDetail> > AddBuilding(string name, int siteId, string area)
        {
            try
            {
                if (!await _context.Buildings.AnyAsync(x => x.Name.ToLower() == name.ToLower()))
                {
                    if (await _context.Sites.AnyAsync(x => x.Id == siteId))
                    {
                        await _context.Buildings.AddAsync(new Building
                        {
                            Name    = name,
                            Area    = area,
                            SitesId = siteId
                        });

                        if (await _context.SaveChangesAsync() == 1)
                        {
                            return(GlobalReturnService.ResponseData(HttpStatusCode.OK, "Success",
                                                                    true));
                        }
                        return(GlobalReturnService.ResponseData(HttpStatusCode.InternalServerError, "Something Went Wrong, while updating entries",
                                                                false));
                    }
                    return(GlobalReturnService.ResponseData(HttpStatusCode.NotFound, "Site Not Found",
                                                            false));
                }
                else
                {
                    return(GlobalReturnService.ResponseData(HttpStatusCode.Conflict, "region already Exist",
                                                            false));
                }
            }
            catch (Exception e)
            {
                return(GlobalReturnService.ResponseData(HttpStatusCode.InternalServerError, "Something Went Wrong, please contact admin",
                                                        false));
            }
        }