コード例 #1
0
        public ActionResult Create(DataViewModel postModel, FormCollection formValues)
        {
            DataCreateModel dataCreateModel = CreateModel(postModel, formValues,Operation.Create);
            DataViewModel model = dataCreateModel.Model;
            foreach(Field field in model.Form.Fields.Where(m => m.FieldTypeId == 11))
            {
                field.Data = Request.UserHostAddress;
            }

            if (ModelState.IsValid)
            {
                RepositoryMapguide repositoryMapGuide = new RepositoryMapguide();
                model = repositoryMapGuide.Add(model);
                dataCreateModel.Model = model;
                repositoryMapGuide.SendEmails(dataCreateModel);
                Models.View endView = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 7);
                if (endView == null)
                {
                    Models.View listUser = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 6);
                    if (listUser == null)
                    {
                        Models.View listAll = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 5);
                        if (listAll == null)
                        {
                            return View(model.View.Name, model);
                        }
                        else
                        {
                            return RedirectToAction("Index", new { id = listAll.ViewId, formId = model.Form.FormId });
                        }
                    }
                    else
                    {
                        return RedirectToAction("Index", new { id = listUser.ViewId, formId = model.Form.FormId });
                    }

                }
                else
                {
                    ViewBag.Id = model.View.ViewId;
                    model.View = endView;
                    return View(endView.Name, model);
                }
            }
            else
                return View(model.View.Name, model);
        }
コード例 #2
0
        //public async Task<HttpResponseMessage> PostFormData()
        public Task<HttpResponseMessage> PostFormData()
        {
            string root = HttpContext.Current.Server.MapPath("~/App_Data");
            /*StreamWriter log1;
            string file1 = Path.Combine(@"d:\inetpub\wwwroot\rapportfrastedet\app_data\", "log1.txt");
            if (!File.Exists(file1))
            {
                log1 = new StreamWriter(file1);
            }
            else
            {
                log1 = File.AppendText(file1);
            }

            // Write to the file:
            log1.WriteLine(DateTime.Now);
            log1.WriteLine(root);

            // Close the stream:
            log1.Close();
            */
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = new MultipartFormDataStreamProvider(root);

            /**/
            // Read the form data.
            //await Request.Content.ReadAsMultipartAsync(provider);
            return Request.Content.ReadAsMultipartAsync(provider).ContinueWith(data =>
            {//.Wait();

                // This illustrates how to get the file names.
                /*foreach (MultipartFileData file in provider.FileData)
                {
                    Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                    Trace.WriteLine("Server file path: " + file.LocalFileName);
                }*/
                try
                {
                    HttpContextWrapper http = (HttpContextWrapper)Request.Properties["MS_HttpContext"];
                    HttpContext.Current = http.ApplicationInstance.Context;
                    RepositorySaveData r = new RepositorySaveData();
                    DataCreateModel dataCreateModel = r.CreateModel(data.Result.FormData, data.Result.FileData, Operation.Create);
                    DataViewModel model = dataCreateModel.Model;

                    foreach (Field field in model.Form.Fields)
                    {
                        if (field.FieldTypeId == 11)
                            field.Data = http.Request.UserHostAddress;
                    }
                    RepositoryMapguide repositoryMapGuide = new RepositoryMapguide();
                    model = repositoryMapGuide.Add(model);
                    dataCreateModel.Model = model;
                    repositoryMapGuide.SendEmails(dataCreateModel);
                    return Request.CreateResponse(HttpStatusCode.OK);
                }
                catch (System.Exception e)
                {
                    StreamWriter log;
                    string file = Path.Combine(root, "log.txt");
                    if (!File.Exists(file))
                    {
                        log = new StreamWriter(file);
                    }
                    else
                    {
                        log = File.AppendText(file);
                    }

                    // Write to the file:
                    log.WriteLine(DateTime.Now);
                    log.WriteLine(e.Message);
                    log.WriteLine(e.StackTrace);

                    // Close the stream:
                    log.Close();
                    HttpResponseMessage r = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
                    System.Net.Http.Headers.MediaTypeWithQualityHeaderValue json = new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json");
                    System.Net.Http.Headers.MediaTypeWithQualityHeaderValue plain = new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/plain");
                    if (!Request.Headers.Accept.Contains(json))
                    {
                        r.Content.Headers.ContentType = plain;
                    }
                    return r;

                }
            });
コード例 #3
0
        public ActionResult Edit(DataViewModel postModel, FormCollection formValues)
        {
            DataCreateModel dataCreateModel = CreateModel(postModel, formValues,Operation.Edit);
            DataViewModel model = dataCreateModel.Model;
            if (ModelState.IsValid)
            {
                RepositoryMapguide repositoryMapGuide = new RepositoryMapguide();
                repositoryMapGuide.Update(model);
                repositoryMapGuide.SendEmails(dataCreateModel);
                Models.View list = null;
                try
                {
                    list = model.View.Group.Views.Single(m => m.ViewTypeId == 5);
                }
                catch { }
                Models.View endView = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 7);
                if (endView == null)
                {
                    Models.View listUser = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 6);
                    if (listUser == null)
                    {
                        Models.View listAll = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 5);
                        if (listAll == null)
                        {
                            return View(model.View.Name, model);
                        }
                        else
                        {
                            return RedirectToAction("Index", new { id = listAll.ViewId, formId = model.Form.FormId });
                        }
                    }
                    else
                    {
                        return RedirectToAction("Index", new { id = listUser.ViewId, formId = model.Form.FormId });
                    }

                }
                else
                {
                    ViewBag.Id = model.View.ViewId;
                    model.View = endView;
                    return View(endView.Name, model);
                }
            }
            else
                return View(model.View.Name, model);
        }
コード例 #4
0
        public ActionResult Delete(DataViewModel postModel)
        {
            RepositoryMapguide mapguide = new RepositoryMapguide();
            RepositoryViews repository = new RepositoryViews();
            Models.View view = repository.Get(postModel.View.ViewId);
            DataViewModel model = new DataViewModel
            {
                View = view,
                Form = view.Group.Forms.Single(m => m.FormId == postModel.Form.FormId),
                ItemId = postModel.ItemId,
                UniqueId = postModel.UniqueId
            };
            model = mapguide.Get(model);
            mapguide.Delete(model);
            List<DataEmailModel> emails = new List<DataEmailModel>();
            if (!String.IsNullOrEmpty(model.Form.Email)&&!String.IsNullOrEmpty(model.Form.ViewEmailToReceiverOnDelete))
            {
                emails.Add(new DataEmailModel { Email = model.Form.Email, View = model.Form.ViewEmailToReceiverOnDelete });
            }
            foreach (Field field in model.Form.Fields)
            {
                if (field.FieldTypeId == 7)
                {
                    if (!string.IsNullOrEmpty(field.Data))
                    {
                        if (email.IsMatch(field.Data))
                        {
                            string emailView = field.Form.ViewEmailToSenderOnDelete;
                            Field operationField = field.Form.Fields.FirstOrDefault(m => m.FieldTypeId == 13);
                            if (!String.IsNullOrEmpty(emailView) && operationField != null)
                            {
                                if (!String.IsNullOrEmpty(operationField.Data))
                                {
                                    if (operationField.Data == "1" || operationField.Data == "True")
                                    {
                                        emails.Add(new DataEmailModel { Email = field.Data, View = emailView });
                                    }
                                }

                            }
                        }
                    }
                }
                Selection selection = field.Selections.SingleOrDefault(m => m.Name == field.Data);
                if (selection != null && !String.IsNullOrEmpty(model.Form.ViewEmailToReceiverOnDelete))
                {

                    if (!String.IsNullOrEmpty(selection.Email))
                    {
                            emails.Add(new DataEmailModel { Email = selection.Email, View = model.Form.ViewEmailToReceiverOnDelete });
                    }
                }
            }
            DataCreateModel dcm = new DataCreateModel()
            {
                Model = model,
                Emails = emails
            };
            mapguide.SendEmails(dcm);
            Models.View endView = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 7);
            if (endView == null)
            {
                Models.View listUser = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 6);
                if (listUser == null)
                {
                    Models.View listAll = model.View.Group.Views.SingleOrDefault(m => m.ViewTypeId == 5);
                    if (listAll == null)
                    {
                        return View(model.View.Name, model);
                    }
                    else
                    {
                        return RedirectToAction("Index", new { id = listAll.ViewId, formId = model.Form.FormId });
                    }
                }
                else
                {
                    return RedirectToAction("Index", new { id = listUser.ViewId, formId = model.Form.FormId });
                }

            }
            else
            {
                return View(endView.Name, model);
            }
        }