public Certification SaveUserCertification(dtoCertification dto) { Certification certification = null; try { Manager.BeginTransaction(); Person person = Manager.GetPerson(UC.CurrentUserID); Person owner = Manager.GetPerson(dto.IdOwner); if (owner != null && owner.TypeID != (int)UserTypeStandard.Guest && person != null) { List <Certification> items = (from c in Manager.GetIQ <Certification>() where c.Deleted == BaseStatusDeleted.None && c.SourceItem.Equals(dto.SourceItem) && c.Owner.Id == dto.IdOwner && c.Type == dto.Type select c).ToList().OrderByDescending(c => c.CreatedOn).ToList(); Guid uId = Guid.NewGuid(); if (items.Count > 0) { uId = items.Select(c => c.UniqueId).FirstOrDefault(); items.Where(i => i.Status == CertificationStatus.Valid).ToList().ForEach(i => i.Status = CertificationStatus.OverWritten); } certification = new Certification(); certification.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); certification.IssuedOn = DateTime.Now; certification.SourceItem = dto.SourceItem; certification.Status = dto.Status; certification.Type = dto.Type; certification.Owner = owner; certification.SourceIdContainer = dto.IdContainer; certification.UniqueId = uId; certification.Name = dto.Name; certification.Description = dto.Description; certification.FileUniqueId = dto.UniqueIdGeneratedFile; certification.Community = Manager.GetCommunity(dto.IdCommunity); certification.IdTemplate = dto.IdTemplate; certification.IdTemplateVersion = dto.IdTemplateVersion; certification.FileExtension = dto.FileExtension; certification.WithEmptyPlaceHolders = dto.WithEmptyPlaceHolders; Manager.SaveOrUpdate(certification); } Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); certification = null; } return(certification); }