public void Save(Location entity)
        {
            ValidationResultInfo vri = Validate(entity);
            if (!vri.IsValid)
                throw new DomainValidationException(vri, "Location  Details not Valid");
            DateTime date = DateTime.Now;
            Location tbl = _context.Locations.FirstOrDefault(s => s.Id == entity.Id);
            if (tbl == null)
            {
                tbl = new Location();
                tbl.CreatedOn = date;
                tbl.IsActive = true;
                tbl.Id = entity.Id;
                _context.Locations.Add(tbl);
            }
            tbl.Name = entity.Name;

            tbl.Description = entity.Description;
            tbl.StructureId = entity.StructureId;
            tbl.Code = entity.Code;
            tbl.ParentId = entity.ParentId ?? Guid.Empty;

            tbl.UpdatedOn = date;

            _context.SaveChanges();
        }
        public BasicResponse Save(LocationDTO dto)
        {
            var response = new BasicResponse();
            try
            {
                var entity = new Location
                {
                    Code = dto.Code,
                    Id = dto.Id,
                    Name = dto.Name,
                    Description = dto.Description,
                    StructureId =(LocationStructure) dto.LocationStructureId,
                    IsActive = true,
                };
                _locationRepository.Save(entity);
                response.Status = true;
                response.Info = "Success";

            }

            catch (Exception ex)
            {
                response.Status = false;
                if (ex is DomainValidationException)
                {
                    var dex = ex as DomainValidationException;
                    response.Info = dex.FormatException();
                }
                else
                {
                    response.Status = false;
                    response.Info = ex.Message;
                }

            }
            return response;
        }
        private LocationDTO Map(Location entity)
        {
            if (entity == null)
                return null;
            var dto = new LocationDTO
            {
                Code = entity.Code,
                Id = entity.Id,
                IsActive = entity.IsActive,
                Name = entity.Name,
                Description = entity.Description,
                LocationStructureId =(int) entity.StructureId,
                LocationStructureName = entity.StructureId.ToString(),

            };
            return dto;
        }
 public ValidationResultInfo Validate(Location itemToValidate)
 {
     return itemToValidate.BasicValidation();
 }