Пример #1
0
        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();
        }
Пример #2
0
        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;
        }
Пример #3
0
        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;
        }
Пример #4
0
 public ValidationResultInfo Validate(Location itemToValidate)
 {
     return itemToValidate.BasicValidation();
 }