public ReturnMessageModel CreateResourceCopies(ResourceGenerationModel rgModel) { try { using (PointOfSaleEntities context = new PointOfSaleEntities()) { var gRow = new ResourceGeneration(); gRow.ResourceId = rgModel.ResourceId; gRow.Remarks = rgModel.Remarks; gRow.GenerationCopyCount = rgModel.GenerationCopyCount; gRow.GenerationDate = CommonService.GetEnglishDate(rgModel.GenerationDateNepali); context.ResourceGenerations.Add(gRow); context.SaveChanges(); //for Resoruce copies for (int i = 0; i < rgModel.GenerationCopyCount; i++) { var rRow = new ResourceCopy(); rRow.GenerationId = gRow.GenerationId; rRow.ResourceId = rgModel.ResourceId; rRow.ResourceCopyCount = i + 1; rRow.ResourceCopyNumber = rgModel.ResourceName + "-" + rgModel.ResourceId.ToString() + ":" + gRow.GenerationId.ToString() + ":" + i.ToString(); rRow.Remarks = rgModel.Remarks; rRow.IsAvailable = rgModel.IsAvailable; rRow.PublishedDate = CommonService.GetEnglishDate(rgModel.GenerationDateNepali); rRow.Edition = "new edition"; context.ResourceCopies.Add(rRow); } context.SaveChanges(); rModel.Msg = "SUceess"; rModel.Success = true; return(rModel); } } catch (Exception ex) { rModel.Msg = "fail"; rModel.Success = false; return(rModel); } }
public ReturnMessageModel CreateResourceGeneration(ResourceGenerationModel rgModel) { try { using (PointOfSaleEntities _context = new PointOfSaleEntities()) { var rtRow = _context.ResourceGenerations.Where(x => x.GenerationId == rgModel.GenerationId).FirstOrDefault(); if (rtRow == null) { rtRow = new ResourceGeneration(); } rtRow.ResourceId = rgModel.ResourceId; //rtRow.GenerationDate = rgModel.GenerationDate; rtRow.GenerationCopyCount = rgModel.GenerationCopyCount; rtRow.Remarks = rgModel.Remarks; if (rgModel.GenerationId == 0) { rtRow.GenerationDate = System.DateTime.Now; _context.ResourceGenerations.Add(rtRow); _context.SaveChanges(); } else { _context.ResourceGenerations.Attach(rtRow); _context.Entry(rtRow).State = EntityState.Modified; _context.SaveChanges(); } var gRow = _context.ResourceCopies.Where(x => x.ResourceCopyId == rgModel.ResourceCopyId).FirstOrDefault(); if (gRow == null) { gRow = new ResourceCopy(); } for (int i = 1; i < rgModel.GenerationCopyCount; i++) { gRow.ResourceCopyId = rgModel.ResourceCopyId; gRow.ResourceId = rgModel.ResourceId; gRow.GenerationId = rgModel.GenerationId; gRow.ResourceCopyCount = i; //gRow.ResourceCopyNumber = ResourceId.ToString() + rgModel.GenerationId + rgModel.ResourceCopyId; } //rtRow.GenerationId rModel.Msg = "Resource Type Saved Successfully"; rModel.Success = true; return(rModel); } } catch (Exception ex) { rModel.Msg = "Resource Type Saved Failed"; rModel.Success = false; return(rModel); } }