Exemple #1
0
        public ActionResult AddProject(project model)
        {
            MessageModel result = new MessageModel();

            try
            {
                if (string.IsNullOrEmpty(model.name))
                {
                    result.State   = 0;
                    result.Messgae = "项目不能为空";
                    return(Json(result));
                }
                if (model.firstcompanyid == null || model.firstcompanyid == 0)
                {
                    result.State   = 0;
                    result.Messgae = "合作公司不能为空";
                    return(Json(result));
                }
                if (model.secondcompanyid == null || model.secondcompanyid == 0)
                {
                    result.State   = 0;
                    result.Messgae = "承接公司不能为空";
                    return(Json(result));
                }


                var item = db.project.SingleOrDefault(p => p.name == model.name);
                if (item != null)
                {
                    result.State   = 0;
                    result.Messgae = "该项目名已经存在";
                    return(Json(result));
                }
                string t        = Session["userinfo"].ToString();
                user   now_user = JsonConvert.DeserializeObject <user>(t);
                model.createtime = DateTime.Now;
                model.userid     = now_user.id;
                var fileArray1 = string.IsNullOrWhiteSpace(model.earlyfiles) ? new string[0] : model.earlyfiles.Split(';').Where(p => p != "").ToArray();
                model.earlyfiles = fileArray1.Length > 1 ? string.Join(";", fileArray1) : (fileArray1.Length == 0 ? "" : fileArray1[0]);
                var fileArray2 = string.IsNullOrWhiteSpace(model.solutionfiles) ? new string[0] : model.solutionfiles.Split(';').Where(p => p != "").ToArray();
                model.solutionfiles = fileArray2.Length > 1 ? string.Join(";", fileArray2) : (fileArray2.Length == 0 ? "" : fileArray2[0]);
                var fileArray3 = string.IsNullOrWhiteSpace(model.finalfiles) ? new string[0] : model.finalfiles.Split(';').Where(p => p != "").ToArray();
                model.finalfiles = fileArray3.Length > 1 ? string.Join(";", fileArray3) : (fileArray3.Length == 0 ? "" : fileArray3[0]);
                db.project.Add(model);
                db.SaveChanges();
                result.State   = 1;
                result.Messgae = "添加成功";
                return(Json(result));
            }catch (Exception ex)
            {
                result.State   = 0;
                result.Messgae = ex.ToString();
                return(Json(result));
            }
        }
Exemple #2
0
        public ActionResult AddCompany(AddCompanyModel AddItem)
        {
            MessageModel result = new MessageModel();

            try
            {
                if (string.IsNullOrEmpty(AddItem.Company.name))
                {
                    result.State   = 0;
                    result.Messgae = "公司名不能为空";
                    return(Json(result));
                }
                var tagids   = "";
                var modelids = "";
                //添加model
                for (var i = 0; i < AddItem.Models.Count(); i++)
                {
                    if (i > 0)
                    {
                        modelids += ",";
                    }
                    AddItem.Models[i].typeids = AddItem.Models[i].typeids == null ? "" : AddItem.Models[i].typeids;
                    db.model.Add(AddItem.Models[i]);
                    db.SaveChanges();
                    modelids += AddItem.Models[i].id;
                    var fileArray = string.IsNullOrWhiteSpace(AddItem.Models[i].file) ? new string[0] : AddItem.Models[i].file.Split(';').Where(t => t != "").ToArray();
                    AddItem.Models[i].file = fileArray.Length > 1 ? string.Join(";", fileArray) : (fileArray.Length == 0 ? "" : fileArray[0]);
                    if (AddItem.Models[i].typeids != null)
                    {
                        tagids += (tagids == "" ? "" : ",") + AddItem.Models[i].typeids;
                    }
                }

                var item = db.Company.SingleOrDefault(t => t.name == AddItem.Company.name & t.type == AddItem.Company.type);
                if (item != null)
                {
                    result.State   = 0;
                    result.Messgae = "该公司名已经存在";
                    return(Json(result));
                }
                tagids = ArrayChange.StrsToStr(tagids.Split(',').Distinct().ToArray());
                AddItem.Company.tagids   = tagids;
                AddItem.Company.modelids = modelids;
                var fileArray2 = string.IsNullOrWhiteSpace(AddItem.Company.description) ? new string[0] : AddItem.Company.description.Split(';').Where(t => t != "").ToArray();
                AddItem.Company.description = fileArray2.Length > 1 ? string.Join(";", fileArray2) : (fileArray2.Length == 0 ? "" : fileArray2[0]);
                db.Company.Add(AddItem.Company);
                db.SaveChanges();
                result.State   = 1;
                result.Messgae = "添加成功";
                return(Json(result));
            }
            catch (Exception ex)
            {
                result.State   = 0;
                result.Messgae = ex.ToString();
                return(Json(result));
            }
        }