예제 #1
0
 public UploadedFile Upload(Stream Uploading)
 {
     try
     {
         using (MemoryStream memStream = new MemoryStream())
         {
             Uploading.CopyTo(memStream);
             Byte[]            bytes  = memStream.ToArray();
             CollegeMSEntities cme    = new CollegeMSEntities();
             Upload            upload = cme.Uploads.Create();
             upload.File        = bytes;
             upload.CreatedDate = DateTime.Now;
             upload             = cme.Uploads.Add(upload);
             cme.SaveChanges();
             return(new UploadedFile()
             {
                 ID = upload.ID, Message = "Uploaded successfully.", ResponseCode = 0
             });
         }
     }
     catch (Exception ex)
     {
         return(new UploadedFile()
         {
             UploadType = "Uplod failed", Message = ex.Message, ResponseCode = -1, ID = 0
         });
     }
 }
    public string UpdateRegistration(int RegistrationId, int UploadId, string FilePath)
    {
        try
        {
            string filename    = Path.GetFileName(FilePath);
            string ext         = Path.GetExtension(filename);
            string contenttype = String.Empty;

            switch (ext)
            {
            case ".doc":
                contenttype = "application/vnd.ms-word";
                break;

            case ".docx":
                contenttype = "application/vnd.ms-word";
                break;

            case ".xls":
                contenttype = "application/vnd.ms-excel";
                break;

            case ".xlsx":
                contenttype = "application/vnd.ms-excel";
                break;

            case ".jpg":
                contenttype = "image/jpg";
                break;

            case ".png":
                contenttype = "image/png";
                break;

            case ".gif":
                contenttype = "image/gif";
                break;

            case ".pdf":
                contenttype = "application/pdf";
                break;
            }
            if (contenttype == String.Empty)
            {
                return("File format not recognized.");
            }

            CollegeMSEntities cme          = new CollegeMSEntities();
            Registration      registration = cme.Registrations.Find(RegistrationId);
            registration.UploadId      = UploadId;
            registration.PhotoFileName = registration.FirstName + "_" + registration.LastName + "_" + RegistrationId + ext;
            cme.SaveChanges();
            return("Success");
        }
        catch (Exception ex)
        {
            return(ex.Message);
        }
    }
    public string SaveRegistration(string FName, string LName, string DOBDD, string DOBMM, string DOBYY, string CourseAppliedFor, string Email, string MobileNumber, string Category,
                                   string Nationality, string Address, string District, string Pincode, string DurationInUP, string MotherName, string FatherName, string MotherOccupation, string FatherOccupation,
                                   string MotherIncome, string FatherIncome, string MotherMobile, string FatherMobile, string Cast, string PhoneNumber, string Religion, int IsMinority)
    {
        decimal MIncome, FIncome;

        decimal.TryParse(MotherIncome, out MIncome);
        decimal.TryParse(FatherIncome, out FIncome);
        using (CollegeMSEntities cme = new CollegeMSEntities())
        {
            Registration registration = cme.Registrations.Create();
            registration.FirstName          = FName;
            registration.LastName           = LName;
            registration.DateOfBirth        = DateTime.ParseExact(DOBDD + "/" + DOBMM + "/" + DOBYY, "dd/mm/yyyy", CultureInfo.InvariantCulture);
            registration.CourseId           = long.Parse(CourseAppliedFor);
            registration.Email              = Email;
            registration.MobileNumber       = MobileNumber;
            registration.CategoryID         = int.Parse(Category);
            registration.Nationality        = Nationality;
            registration.AddressLine1       = Address;
            registration.AddressLine2       = District;
            registration.Pincode            = Pincode;
            registration.Duration_in_UP     = decimal.Parse(DurationInUP);
            registration.MotherName         = MotherName;
            registration.FatherName         = FatherName;
            registration.MotherOccupation   = MotherOccupation;
            registration.FatherOccupation   = FatherOccupation;
            registration.MotherIncome       = MIncome;
            registration.FatherIncome       = FIncome;
            registration.MotherMobileNumber = MotherMobile;
            registration.FatherMobileNumber = FatherMobile;
            registration.Cast        = Cast;
            registration.PhoneNumber = PhoneNumber;
            registration.Religion    = Religion;
            registration.IsMinority  = (1 == IsMinority);

            registration = cme.Registrations.Add(registration);
            cme.SaveChanges();
            return(Newtonsoft.Json.JsonConvert.SerializeObject(new { ID = registration.ID, FirstName = registration.FirstName, LastName = registration.LastName, ResponseCode = 0, Message = "Success" }));
        }
    }