public ServiceResponse <Guid> SaveCibmtr(CibmtrItem model)
        {
            if (!base.IsFactStaff)
            {
                return(new ServiceResponse <Guid>
                {
                    HasError = true,
                    Message = "Not Authorized"
                });
            }

            try
            {
                var facade  = this.Container.GetInstance <FacilityFacade>();
                var recorrd = facade.SaveCibmtr(model, base.Email);

                return(new ServiceResponse <Guid>
                {
                    Item = recorrd.Id
                });
            }
            catch (Exception ex)
            {
                return(base.HandleException <Guid>(ex));
            }
        }
Exemplo n.º 2
0
        public FacilityCibmtr SaveCibmtr(CibmtrItem item, string savedBy)
        {
            var facilityCibmtrManager = this.container.GetInstance <FacilityCibmtrManager>();
            var facilityManager       = this.container.GetInstance <FacilityManager>();

            if (item.Id.HasValue)
            {
                var record = facilityCibmtrManager.GetById(item.Id.Value);

                if (record == null)
                {
                    throw new Exception("Cannot find CIBMTR record");
                }

                if (record.CenterNumber != item.CenterNumber && !this.IsCibmtrNameUnique(record.CenterNumber))
                {
                    throw new Exception($"{item.CenterNumber} is not unique. Please enter a unique name.");
                }

                record.CenterNumber = item.CenterNumber;
                record.CcnName      = item.CcnName;
                record.TransplantSurvivalReportName = item.TransplantSurvivalReportName;
                record.DisplayName = item.DisplayName;
                record.IsNonCibmtr = item.IsNonCibmtr;
                record.IsActive    = item.IsActive;
                record.UpdatedBy   = savedBy;
                record.UpdatedDate = DateTime.Now;

                facilityCibmtrManager.Save(record);

                return(record);
            }
            else
            {
                var facility = facilityManager.GetByName(item.FacilityName);

                if (facility == null)
                {
                    throw new Exception($"Cannot find Facility {item.FacilityName}");
                }

                if (!this.IsCibmtrNameUnique(item.CenterNumber))
                {
                    throw new Exception($"{item.CenterNumber} is not unique. Please enter a unique name.");
                }

                var record = new FacilityCibmtr
                {
                    Id           = Guid.NewGuid(),
                    CenterNumber = item.CenterNumber,
                    CcnName      = item.CcnName,
                    TransplantSurvivalReportName = item.TransplantSurvivalReportName,
                    DisplayName = item.DisplayName,
                    IsNonCibmtr = item.IsNonCibmtr,
                    FacilityId  = facility.Id,
                    CreatedBy   = savedBy,
                    CreatedDate = DateTime.Now,
                    IsActive    = item.IsActive
                };

                facilityCibmtrManager.Add(record);

                return(record);
            }
        }