public void Create(ProtocolW protocolW)
        {
            var acreditedLevel = Db.AcredetationLevels.Single(al => al.Level.Trim() == AcreditationLevels.Acredited);

            foreach (var remark in protocolW.ProtocolsRemarksA)
            {
                remark.AcredetationLevelId = acreditedLevel.Id;
                remark.Remark = Db.Remarks.Single(r => r.Id == remark.RemarkId);
            }

            var notAcreditedLevel = Db.AcredetationLevels.Single(al => al.Level.Trim() == AcreditationLevels.NotAcredited);

            foreach (var remark in protocolW.ProtocolsRemarksB)
            {
                remark.AcredetationLevelId = notAcreditedLevel.Id;
                remark.Remark = Db.Remarks.Single(r => r.Id == remark.RemarkId);
            }

            var protocol = protocolW.ToBase();

            protocol.IssuedDate = protocol.IssuedDate;
            Db.Protocols.Add(protocol);
            var request = Db.Requests.Single(r => r.Id == protocol.RequestId);

            GeneratePorotocolReport(protocol, request);

            Db.SaveChanges();
        }
        public ActionResult Edit(ProtocolW protocol)
        {
            if (ModelState.IsValid)
            {
                _rep.EditProtocol(protocol);
                return(RedirectToAction("Index"));
            }

            ViewBag.RemarkId = new SelectList(_rep.GetRemarks(), "Id", "Text");
            return(View(protocol));
        }
        public void EditProtocol(ProtocolW protocolW)
        {
            var protocol = Db.Protocols.Single(p => p.Id == protocolW.Id);

            Db.ProtocolResults.RemoveRange(protocol.ProtocolResults);
            protocol.ProtocolResults.Clear();
            foreach (var item in protocolW.ProtocolResults)
            {
                protocol.ProtocolResults.Add(item);
            }

            Db.ProtocolsRemarks.RemoveRange(protocol.ProtocolsRemarks);
            protocol.ProtocolsRemarks.Clear();
            var acreditedLevel = Db.AcredetationLevels.Single(al => al.Level.Trim() == AcreditationLevels.Acredited);

            foreach (var item in protocolW.ProtocolsRemarksA)
            {
                item.AcredetationLevelId = acreditedLevel.Id;

                //for some reason the saveChanges doesnt populate the Remark object in the ProtocolsRemark and its
                //needed inside the protocol generating
                item.Remark = Db.Remarks.Single(r => r.Id == item.RemarkId);
                protocol.ProtocolsRemarks.Add(item);
            }

            var notAcreditedLevel = Db.AcredetationLevels.Single(al => al.Level.Trim() == AcreditationLevels.NotAcredited);

            foreach (var item in protocolW.ProtocolsRemarksB)
            {
                item.AcredetationLevelId = notAcreditedLevel.Id;

                //for some reason the saveChanges doesnt populate the Remark object in the ProtocolsRemark and its
                //needed inside the protocol generating
                item.Remark = Db.Remarks.Single(r => r.Id == item.RemarkId);
                protocol.ProtocolsRemarks.Add(item);
            }

            protocol.IssuedDate = protocolW.IssuedDate;
            protocol.Tester     = protocolW.Tester;
            protocol.LabLeader  = protocolW.LabLeader;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                Db.SaveChanges();
                GeneratePorotocolReport(protocol);

                scope.Complete();
            }
        }
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProtocolW protocol = _rep.GetProtocol(id.Value);

            if (Request.IsAjaxRequest())
            {
                return(PartialView(protocol));
            }

            return(View(protocol));
        }
Ejemplo n.º 5
0
        public static ProtocolW ToProtocolWrapper(this Protocol entity)
        {
            var protocolW = new ProtocolW()
            {
                Id                = entity.Id,
                RequestId         = entity.Id,
                IssuedDate        = entity.IssuedDate,
                Tester            = entity.Tester,
                LabLeader         = entity.LabLeader,
                ProtocolResults   = entity.ProtocolResults,
                Request           = entity.Request,
                ProtocolsRemarksA = entity.ProtocolsRemarks.Where(pr => pr.AcredetationLevel.Level.Trim() == AcreditationLevels.Acredited),
                ProtocolsRemarksB = entity.ProtocolsRemarks.Where(pr => pr.AcredetationLevel.Level.Trim() == AcreditationLevels.NotAcredited)
            };

            return(protocolW);
        }
 public ActionResult Create(ProtocolW protocol)
 {
     _rep.Create(protocol);
     return(RedirectToAction("Index", "Requests"));
 }