private Guid CreateDocument(List<Employee> emps, Random r)
        {
            Guid id = Guid.NewGuid();

            DateTime opStart = DateTime.Now;
            using (var context = new DataModelDataContext())
            {
                var author = emps[r.Next(0, emps.Count)];
                var controller = emps[r.Next(0, emps.Count)];

                var doc = new Document();
                doc.Id = id;
                doc.AuthorId = author.Id;
                doc.StateName = "Draft";
                doc.Name = "AG_Doc " + doc.Number.ToString();

                if (r.Next(0, 2) == 1)
                {
                    doc.EmloyeeControlerId = controller.Id;
                }
                doc.Comment = string.Format("Auto-generated documnet. {0}.", DateTime.Now.ToShortTimeString());
                doc.Sum = r.Next(1, 10000);

                context.Documents.InsertOnSubmit(doc);
                context.SubmitChanges();
            }

            AddOperation(opStart, DateTime.Now, "CreatingDocument");

            return id;
        }
Exemplo n.º 2
0
 partial void DeleteDocument(Document instance);
Exemplo n.º 3
0
 partial void UpdateDocument(Document instance);
Exemplo n.º 4
0
 partial void InsertDocument(Document instance);
Exemplo n.º 5
0
		private void detach_Documents1(Document entity)
		{
			this.SendPropertyChanging();
			entity.Employee1 = null;
		}
Exemplo n.º 6
0
		private void attach_Documents(Document entity)
		{
			this.SendPropertyChanging();
			entity.Employee = this;
		}
 private DocumentModel GetDocumentModel(Document d)
 {
     return new DocumentModel()
     {
         Id = d.Id,
         AuthorId = d.AuthorId,
         AuthorName = d.Employee1.Name,
         Comment = d.Comment,
         EmloyeeControlerId = d.EmloyeeControlerId,
         EmloyeeControlerName = d.EmloyeeControlerId.HasValue ? d.Employee.Name : string.Empty,
         Name = d.Name,
         Number = d.Number,
         StateName = d.StateName,
         Sum = d.Sum
     };
 }
        public ActionResult Edit(Guid? Id, DocumentModel model, string button)
        {
            using (var context = new DataModelDataContext())
            {
                if (!ModelState.IsValid)
                {
                    return View(model);
                }

                Document target = null;
                if (model.Id != Guid.Empty)
                {
                    target = context.Documents.SingleOrDefault(d=>d.Id == model.Id);
                    if (target == null)
                    {
                        ModelState.AddModelError("", "Row not found!");
                        return View(model);
                    }
                }
                else
                {
                    target = new Document();
                    target.Id = Guid.NewGuid();
                    target.AuthorId = model.AuthorId;
                    target.StateName = model.StateName;
                    context.Documents.InsertOnSubmit(target);
                }

                target.Name = model.Name;
                target.EmloyeeControlerId = model.EmloyeeControlerId;
                target.Comment = model.Comment;
                target.Sum = model.Sum;

                try
                {
                    context.SubmitChanges();
                }
                catch (Exception ex)
                {
                    var sb = new StringBuilder("Ошибка сохранения. " + ex.Message);
                    if (ex.InnerException != null)
                        sb.AppendLine(ex.InnerException.Message);
                    ModelState.AddModelError("", sb.ToString());
                    return View(model);
                }

                if (button == "SaveAndExit")
                    return RedirectToAction("Index");
                if (button != "Save")
                {
                    ExecuteCommand(target.Id, button, model);
                }
                return RedirectToAction("Edit", new {target.Id});
            }
            return View(model);
        }